wroc_love 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,51 @@
1
+ .rvmrc
2
+ Gemfile.lock
3
+
4
+ # rcov generated
5
+ coverage
6
+
7
+ # rdoc generated
8
+ rdoc
9
+
10
+ # yard generated
11
+ doc
12
+ .yardoc
13
+
14
+ # bundler
15
+ .bundle
16
+
17
+ # jeweler generated
18
+ pkg
19
+
20
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
21
+ #
22
+ # * Create a file at ~/.gitignore
23
+ # * Include files you want ignored
24
+ # * Run: git config --global core.excludesfile ~/.gitignore
25
+ #
26
+ # After doing this, these files will be ignored in all your git projects,
27
+ # saving you from having to 'pollute' every project you touch with them
28
+ #
29
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
30
+ #
31
+ # For MacOS:
32
+ #
33
+ #.DS_Store
34
+
35
+ # For TextMate
36
+ #*.tmproj
37
+ #tmtags
38
+
39
+ # For emacs:
40
+ #*~
41
+ #\#*
42
+ #.\#*
43
+
44
+ # For vim:
45
+ #*.swp
46
+
47
+ # For redcar:
48
+ #.redcar
49
+
50
+ # For rubinius:
51
+ #*.rbc
data/Gemfile CHANGED
@@ -1,8 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "launchy", "~> 0.4.0"
4
-
5
- group :development do
6
- gem "bundler", "~> 1.0.0"
7
- gem "jeweler", "~> 1.6.4"
8
- end
3
+ gemspec
data/Rakefile CHANGED
@@ -1,46 +1,2 @@
1
- # encoding: utf-8
1
+ require 'bundler/gem_tasks'
2
2
 
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "wroc_love"
18
- gem.homepage = "http://github.com/drugpl/wroc_love.rb"
19
- gem.license = "MIT"
20
- gem.summary = "wroc_love.rb Conference 2012"
21
- gem.description = "Your personal genie for all your wroc_love.rb 2012 needs!"
22
- gem.email = "wojtowicz.norbert@gmail.com"
23
- gem.authors = ["Norbert Wojtowicz"]
24
- gem.executables << 'wroc_love.rb'
25
- # dependencies defined in Gemfile
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
28
-
29
- require 'rake/testtask'
30
- Rake::TestTask.new(:test) do |test|
31
- test.libs << 'lib' << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
-
36
- task :default => :test
37
-
38
- require 'rake/rdoctask'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
-
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "wroc_love #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
46
- end
data/bin/wroc_love.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: UTF-8
2
3
 
3
4
  require 'launchy'
5
+ require 'wroc_love'
4
6
 
5
7
  def say(msg)
6
8
  puts msg
@@ -21,7 +23,8 @@ Commands:
21
23
  map Launch Google map
22
24
  follow Follow us on Twitter
23
25
  tweet Spread the word!
24
- EOF
26
+ flights Check flights to Wrocław from airports near you!
27
+ EOF
25
28
  end
26
29
 
27
30
  cmd = ARGV.shift
@@ -37,4 +40,27 @@ when "follow"
37
40
  Launchy.open("http://twitter.com/wrocloverb")
38
41
  when "tweet"
39
42
  Launchy.open("http://twitter.com/home?status=Fresh%20Ruby-oriented%20conference%20in%20Wroc%C5%82aw%2C%20Poland.%20Get%20ready%20March%202012%3A%20http%3A%2F%2Fwrocloverb.com%20Please%20RT")
43
+ when "flights"
44
+ require 'geocoder'
45
+ require 'socket'
46
+ require 'net/http'
47
+ require 'uri'
48
+
49
+ url = "http://automation.whatismyip.com/n09230945.asp".freeze
50
+
51
+ uri = URI.parse(url)
52
+ res = Net::HTTP.start(uri.host, uri.port) {|http|
53
+ http.get(uri.path)
54
+ }
55
+ ip = res.body
56
+ puts "it seems that your public ip is: #{ip}"
57
+ location = Geocoder.search(ip).first
58
+ loc = [location.latitude, location.longitude]
59
+ # loc = [51.1, 17.0333] Wrocław
60
+ puts "so we guess that your location is: #{loc}"
61
+
62
+ puts "let's try to find some airports near you (visit the link to check the flights to Wrocław):"
63
+ WrocLove::Airport.nearest(loc).each do |airport|
64
+ puts airport.description
65
+ end
40
66
  end
@@ -0,0 +1,34 @@
1
+ require 'geocoder'
2
+
3
+ module WrocLove
4
+ class Airport < Struct.new(:code, :name, :location)
5
+
6
+ TimeFormatRule = "%y%m%d".freeze
7
+
8
+ class << self
9
+ attr_accessor :airports
10
+ private :airports, :airports=
11
+
12
+ def store(*params)
13
+ airports << new(*params).freeze
14
+ end
15
+
16
+ def nearest(location, count = 10)
17
+ airports.sort_by{|a| Geocoder::Calculations.distance_between(a.location, location) }.first(count)
18
+ end
19
+
20
+ end
21
+
22
+ self.airports = []
23
+
24
+ def description
25
+ "#{code.rjust(5)} #{name.rjust(35)} #{link}"
26
+ end
27
+
28
+ def link
29
+ "http://www.skyscanner.net/flights/#{code.downcase}/wro/#{WrocLove::Arrival.strftime(TimeFormatRule)}/#{WrocLove::Return.strftime(TimeFormatRule)}"
30
+ end
31
+ end
32
+ end
33
+
34
+ require 'wroc_love/airports'