auntie 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +49 -0
  4. data/LICENSE +20 -0
  5. data/README.md +39 -0
  6. data/Rakefile +24 -0
  7. data/bin/news +4 -0
  8. data/bin/radio +51 -0
  9. data/bin/sport +4 -0
  10. data/bin/tv +45 -0
  11. data/bin/weather +23 -0
  12. data/features/location.feature +8 -0
  13. data/features/news.feature +8 -0
  14. data/features/radio.feature +8 -0
  15. data/features/sport.feature +8 -0
  16. data/features/step_definitions/location_steps.rb +7 -0
  17. data/features/step_definitions/radio_steps.rb +1 -0
  18. data/features/step_definitions/tv_steps.rb +1 -0
  19. data/features/step_definitions/weather_steps.rb +6 -0
  20. data/features/support/env.rb +15 -0
  21. data/features/tv.feature +8 -0
  22. data/features/weather.feature +8 -0
  23. data/lib/auntie.rb +16 -0
  24. data/lib/bbc/location.rb +44 -0
  25. data/lib/bbc/news.rb +28 -0
  26. data/lib/bbc/now_next.rb +93 -0
  27. data/lib/bbc/schedule.rb +53 -0
  28. data/lib/bbc/shell/characters.rb +68 -0
  29. data/lib/bbc/shell/colors.rb +39 -0
  30. data/lib/bbc/shell/describe_time.rb +20 -0
  31. data/lib/bbc/sport.rb +33 -0
  32. data/lib/bbc/version.rb +7 -0
  33. data/lib/bbc/weather.rb +98 -0
  34. data/scratch +9 -0
  35. data/spec/bbc/location_spec.rb +45 -0
  36. data/spec/bbc/news_spec.rb +43 -0
  37. data/spec/bbc/now_next_spec.rb +53 -0
  38. data/spec/bbc/schedule_spec.rb +56 -0
  39. data/spec/bbc/sport_spec.rb +35 -0
  40. data/spec/bbc/version_spec.rb +18 -0
  41. data/spec/bbc/weather_spec.rb +41 -0
  42. data/spec/fixtures/3dayforecast.json +149 -0
  43. data/spec/fixtures/3hourlyforecast.json +265 -0
  44. data/spec/fixtures/location.json +12 -0
  45. data/spec/fixtures/news.json +31 -0
  46. data/spec/fixtures/now_next_radio.json +7767 -0
  47. data/spec/fixtures/now_next_tv.json +3471 -0
  48. data/spec/fixtures/schedule_radio_today.json +939 -0
  49. data/spec/fixtures/schedule_radio_tomorrow.json +941 -0
  50. data/spec/fixtures/schedule_radio_yesterday.json +1118 -0
  51. data/spec/fixtures/schedule_tv.json +1695 -0
  52. data/spec/fixtures/sport.json +38 -0
  53. data/spec/spec_helper.rb +13 -0
  54. metadata +170 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a4896751f96adc8b695d536c3dc46030b1a333af
4
+ data.tar.gz: e8d3f4c3c2831558bc4a88631546c19bb39111c6
5
+ SHA512:
6
+ metadata.gz: c7586efa5622dff643cfe6109093cbfd553a26352373b892910750156e2998cb035f294e5b408ce652b0621fa6df5acaa620a14ba502a7e9c1b995638edf5c29
7
+ data.tar.gz: 4fb2bd9e364e95a60c4505b9881b65b928f0899d2f8dc4f342f24dee87c1ed0b561ec4554ccbb7fde7cc46fe0f4a82cc224ef773a6b5c1b878415e8fe7693d5d
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ auntie (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ anticipate (0.0.2)
10
+ aruba (0.5.0)
11
+ childprocess (= 0.2.3)
12
+ cucumber (>= 1.1.1)
13
+ ffi (>= 1.0.11)
14
+ rspec-expectations (>= 2.7.0)
15
+ builder (3.1.4)
16
+ childprocess (0.2.3)
17
+ ffi (~> 1.0.6)
18
+ cucumber (1.2.1)
19
+ builder (>= 2.1.2)
20
+ diff-lcs (>= 1.1.3)
21
+ gherkin (~> 2.11.0)
22
+ json (>= 1.4.6)
23
+ diff-lcs (1.1.3)
24
+ ffi (1.0.11)
25
+ gherkin (2.11.5)
26
+ json (>= 1.4.6)
27
+ json (1.7.5)
28
+ rake (0.9.2.2)
29
+ rdoc (3.12)
30
+ json (~> 1.4)
31
+ rspec (2.11.0)
32
+ rspec-core (~> 2.11.0)
33
+ rspec-expectations (~> 2.11.0)
34
+ rspec-mocks (~> 2.11.0)
35
+ rspec-core (2.11.1)
36
+ rspec-expectations (2.11.3)
37
+ diff-lcs (~> 1.1.3)
38
+ rspec-mocks (2.11.3)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ anticipate
45
+ aruba
46
+ auntie!
47
+ rake
48
+ rdoc
49
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) MMXIV Simon Gregory
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Auntie
2
+
3
+ A Ruby Gem for accessing [BBC]() weather, tv, radio, news and sport feeds.
4
+
5
+ # Install
6
+
7
+ gem install auntie
8
+
9
+ # Use
10
+
11
+ weather # lists the weather for the next 24 hours
12
+
13
+ tv # what is on BBC One today
14
+ tv two # what is on BBC Two today
15
+ tv now # list of all programmes being broadcast on tv now
16
+
17
+ radio # what is on Radio 1 today
18
+ radio next # what is on the wireless next
19
+ radio six # what is on Radio Six Music
20
+
21
+ news # the latest news headlines
22
+
23
+ sport # the latest sport headlines
24
+
25
+ # zsh integration
26
+
27
+ For zsh-shell completion you'll want to create a file called `_radio` with the following contents:
28
+
29
+ #compdef radio
30
+ compadd `radio help -c`
31
+
32
+ and source it via your .zshrc file. The same can be done for the `tv` and `weather`.
33
+
34
+ # Licence
35
+
36
+ [MIT][], see accomanying [LICENSE](LICENSE) document
37
+
38
+ [BBC]: http://www.bbc.co.uk/
39
+ [MIT]: http://opensource.org/licenses/MIT
@@ -0,0 +1,24 @@
1
+ require 'rake/clean'
2
+ require 'rake/testtask'
3
+ require 'rubygems'
4
+ require 'rspec'
5
+ require 'rspec/core/rake_task'
6
+ require 'cucumber'
7
+ require 'cucumber/rake/task'
8
+
9
+ CLEAN << 'tmp'
10
+
11
+ desc 'Run features'
12
+ Cucumber::Rake::Task.new(:features) do |t|
13
+ t.cucumber_opts = "features --format html -o tmp/results.html --format progress -x"
14
+ t.fork = false
15
+ end
16
+
17
+ desc "Run all examples"
18
+ RSpec::Core::RakeTask.new(:spec) do |t|
19
+ t.rspec_opts = %w[--color]
20
+ end
21
+
22
+ task :t => [:spec]
23
+
24
+ task :default => [:spec, :features]
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'auntie'
3
+
4
+ News.new.load
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ require 'auntie'
3
+
4
+ channels = {
5
+ :one => { :id => 'radio1', :region => '/england' },
6
+ :onextra => { :id => '1xtra' },
7
+ :two => { :id => 'radio2' },
8
+ :three => { :id => 'radio3' },
9
+ :four => { :id => 'radio4', :region => '/fm' },
10
+ :fourextra => { :id => 'radio4extra' },
11
+ :five => { :id => '5live' },
12
+ :six => { :id => '6music' },
13
+ :asian => { :id => 'asiannetwork' },
14
+ :worldservice => { :id => 'worldserviceradio' }
15
+ }
16
+
17
+ channel = ARGV[0] || :one
18
+
19
+ if ARGV[0] == 'help' && ARGV[1] == '-c'
20
+ channels.each { |k,v| puts k }
21
+ puts "now\nnext"
22
+ exit
23
+ end
24
+
25
+ if ['help', '-h', '--help'].include? ARGV[0]
26
+ puts 'Useage: radio <channel>'
27
+ exit
28
+ end
29
+
30
+ if ARGV[0] == 'now'
31
+ NowNext.new.radio_now
32
+ exit
33
+ end
34
+
35
+ if ARGV[0] == 'next'
36
+ NowNext.new.radio_next
37
+ exit
38
+ end
39
+
40
+ if channels.has_key? channel.to_sym
41
+
42
+ selection = channels[channel.to_sym]
43
+
44
+ if ['yesterday', 'today', 'tomorrow'].include? ARGV[1]
45
+ selection[:period] = '/'+ARGV[1]
46
+ end
47
+
48
+ Schedule.new.load selection
49
+ else
50
+ puts "'#{channel}' is an unknown channel"
51
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'auntie'
3
+
4
+ Sport.new.headlines
data/bin/tv ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ require 'auntie'
3
+
4
+ channels = {
5
+ :one => { :id => 'bbcone', :region => '/london' },
6
+ :two => { :id => 'bbctwo', :region => '/england' },
7
+ :three => { :id => 'bbcthree' },
8
+ :four => { :id => 'bbcfour' },
9
+ :cbeebies => { :id => 'cbeebies' },
10
+ :cbbc => { :id => 'cbbc' },
11
+ :news => { :id => 'bbcnews' },
12
+ :parliament => { :id => 'parliament' },
13
+ :alba => { :id => 'alba', }
14
+ }
15
+
16
+ channel = ARGV[0] || :one
17
+
18
+ if ARGV[0] == 'help' && ARGV[1] == '-c'
19
+ channels.each { |k,v| puts k }
20
+ puts "now\nnext"
21
+ exit
22
+ end
23
+
24
+ helps = ['help', '-h', '--help']
25
+
26
+ if helps.include? ARGV[0]
27
+ puts 'Useage: tv <channel>'
28
+ exit
29
+ end
30
+
31
+ if ARGV[0] == 'now'
32
+ NowNext.new.tv_now
33
+ exit
34
+ end
35
+
36
+ if ARGV[0] == 'next'
37
+ NowNext.new.tv_next
38
+ exit
39
+ end
40
+
41
+ if channels.has_key? channel.to_sym
42
+ Schedule.new.load channels[channel.to_sym]
43
+ else
44
+ puts "'#{channel}' is an unknown channel"
45
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ require 'auntie'
3
+
4
+ if ['help', '-h', '--help'].include? ARGV[0]
5
+ puts 'Useage: weather <Postcode or BBC location id>'
6
+ puts ' '
7
+ puts "To find a BBC location id use: weather loc 'search term'"
8
+ exit
9
+ end
10
+
11
+ if ARGV[0] == 'loc'
12
+ place = ARGV[1..-1].join(' ')
13
+
14
+ abort "Please specify a location to search for." if place.empty?
15
+ place = "Hadfield" if place.downcase == 'royston vasey'
16
+
17
+ Location.new.find(place)
18
+ exit
19
+ end
20
+
21
+ location = ARGV[0] ||= '2643743' #'2643743' #Default to London. UK postcodes also work
22
+
23
+ Weather.new(location).hourly
@@ -0,0 +1,8 @@
1
+ Feature: Location
2
+ In order to get the weather for local people
3
+ As a local person
4
+ I want the weather for Royston Vasey
5
+
6
+ Scenario: Finding the weather by place name
7
+ When I enter the place name
8
+ Then a list of potential matches is shown
@@ -0,0 +1,8 @@
1
+ Feature: News
2
+ In order to keep up to date with what's happening in the world
3
+ As a geek
4
+ I want news in my shell
5
+
6
+ Scenario: News help
7
+ When I get help for "news"
8
+ Then the exit status should be 0
@@ -0,0 +1,8 @@
1
+ Feature: Radio
2
+ In order to know what's on the wireless
3
+ As a nerd
4
+ I want to type `radio` and see what could be coming in my ears
5
+
6
+ Scenario: Radio help
7
+ When I get help for "radio"
8
+ Then the exit status should be 0
@@ -0,0 +1,8 @@
1
+ Feature: Sport
2
+ In order to see who's winning the Rugby
3
+ As a nerd
4
+ I want a quick list of sport headlines
5
+
6
+ Scenario: Sport help
7
+ When I get help for "sport"
8
+ Then the exit status should be 0
@@ -0,0 +1,7 @@
1
+ When /^I enter the place name$/ do
2
+ pending
3
+ end
4
+
5
+ Then /^a list of potential matches is shown$/ do
6
+ pending
7
+ end
@@ -0,0 +1 @@
1
+ # todo
@@ -0,0 +1,6 @@
1
+ When /^I get help for "([^"]*)"$/ do |app_name|
2
+ @app_name = app_name
3
+ step %(I run `#{app_name} help`)
4
+ end
5
+
6
+ # Add more step definitions here
@@ -0,0 +1,15 @@
1
+ require 'aruba/cucumber'
2
+
3
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
4
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
5
+
6
+ Before do
7
+ # Using "announce" causes massive warnings on 1.9.2
8
+ @puts = true
9
+ @original_rubylib = ENV['RUBYLIB']
10
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
11
+ end
12
+
13
+ After do
14
+ ENV['RUBYLIB'] = @original_rubylib
15
+ end
@@ -0,0 +1,8 @@
1
+ Feature: TV
2
+ In order to know what's on the box
3
+ As a nerd
4
+ I want to type `tv` and be enlightened
5
+
6
+ Scenario: TV help
7
+ When I get help for "tv"
8
+ Then the exit status should be 0
@@ -0,0 +1,8 @@
1
+ Feature: Weather
2
+ To find out what the heavens might have instore
3
+ As a nerd
4
+ I want the weather in my shell
5
+
6
+ Scenario: Weather help
7
+ When I get help for "weather"
8
+ Then the exit status should be 0
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ require 'open-uri'
4
+ require 'json'
5
+
6
+ require 'bbc/shell/colors'
7
+ require 'bbc/shell/describe_time'
8
+ require 'bbc/shell/characters'
9
+
10
+ require 'bbc/weather'
11
+ require 'bbc/version'
12
+ require 'bbc/sport'
13
+ require 'bbc/schedule'
14
+ require 'bbc/now_next'
15
+ require 'bbc/news'
16
+ require 'bbc/location'
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ class Location
4
+ def initialize(io=STDOUT)
5
+ @io = io
6
+ end
7
+
8
+ def find(place)
9
+ abort "Please use a longer search term" if place.length < 3
10
+
11
+ @io.print "Searching for #{place}..."
12
+
13
+ load(place)
14
+ end
15
+
16
+ def url(term)
17
+ "http://www.bbc.co.uk/locator/default/en-GB/autocomplete.json?search=#{URI::encode(term)}&filter=domestic&ptrt=/"
18
+ end
19
+
20
+ def load(place)
21
+ begin
22
+ raw = open(url(place), 'UserAgent' => AUNTIE::USER_AGENT).read
23
+ data = JSON.parse(raw)
24
+ rescue
25
+ @io.puts "Unable to download location data"
26
+ exit
27
+ end
28
+
29
+ @io.print "\r"
30
+
31
+ if data.empty?
32
+ @io.puts "No locations found matching '#{place}' "
33
+ else
34
+ @io.puts sprintf "%-42s %-10s", 'Place', 'ID'
35
+ data.each do |e|
36
+ name = e['fullName'].split(',')
37
+ place = light_green(name[0]+ ',') + green(name[1])
38
+ id = cyan e['id']
39
+
40
+ @io.puts sprintf "%-60s %-10s", place, id
41
+ end
42
+ end
43
+ end
44
+ end