auntie 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4896751f96adc8b695d536c3dc46030b1a333af
4
- data.tar.gz: e8d3f4c3c2831558bc4a88631546c19bb39111c6
3
+ metadata.gz: fed4976f396372cbd6c5b4c71ced8a439b06f6a6
4
+ data.tar.gz: 6713d54954ef44ba9326eb15995c7a7b8788d05b
5
5
  SHA512:
6
- metadata.gz: c7586efa5622dff643cfe6109093cbfd553a26352373b892910750156e2998cb035f294e5b408ce652b0621fa6df5acaa620a14ba502a7e9c1b995638edf5c29
7
- data.tar.gz: 4fb2bd9e364e95a60c4505b9881b65b928f0899d2f8dc4f342f24dee87c1ed0b561ec4554ccbb7fde7cc46fe0f4a82cc224ef773a6b5c1b878415e8fe7693d5d
6
+ metadata.gz: f7365a73fb95203fe90a2af2d1533207f118f8a0ce251a6a0f0d2f9e1491f9daba0a77746034833fd4478178b443a8ef9308879c96f507b9480e2ef34861638d
7
+ data.tar.gz: d02f68b2fb542075f5f1723ae713c42a36964ae49affada31992e947da2c854313caf81366e86aef620d84ab8a6d36cacf8da43dc723ae6305a0e56542653fc6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- auntie (0.1.0)
4
+ auntie (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,12 +1,15 @@
1
1
  # Auntie
2
2
 
3
- A Ruby Gem for accessing [BBC]() weather, tv, radio, news and sport feeds.
3
+ [![Build Status](https://travis-ci.org/simongregory/auntie.png?branch=master)](https://travis-ci.org/simongregory/auntie)
4
+ [![Code Climate](https://codeclimate.com/github/simongregory/auntie.png)](https://codeclimate.com/github/simongregory/auntie)
4
5
 
5
- # Install
6
+ A Ruby Gem for accessing [BBC]() Weather, TV, Radio, News and Sport feeds.
7
+
8
+ ## Install
6
9
 
7
10
  gem install auntie
8
11
 
9
- # Use
12
+ ## Use
10
13
 
11
14
  weather # lists the weather for the next 24 hours
12
15
 
@@ -22,18 +25,19 @@ A Ruby Gem for accessing [BBC]() weather, tv, radio, news and sport feeds.
22
25
 
23
26
  sport # the latest sport headlines
24
27
 
25
- # zsh integration
28
+ ## zsh integration
26
29
 
27
- For zsh-shell completion you'll want to create a file called `_radio` with the following contents:
30
+ [zsh][] shell completion can be added to the `tv`, `radio` and `weather` tools. Radio, for example, can be enabled by creating a file called `_radio` with the following contents:
28
31
 
29
32
  #compdef radio
30
33
  compadd `radio help -c`
31
34
 
32
- and source it via your .zshrc file. The same can be done for the `tv` and `weather`.
35
+ and source it via your .zshrc file.
33
36
 
34
- # Licence
37
+ ## Licence
35
38
 
36
39
  [MIT][], see accomanying [LICENSE](LICENSE) document
37
40
 
38
41
  [BBC]: http://www.bbc.co.uk/
39
42
  [MIT]: http://opensource.org/licenses/MIT
43
+ [zsh]: http://zsh.sourceforge.net
data/Rakefile CHANGED
@@ -8,9 +8,21 @@ require 'cucumber/rake/task'
8
8
 
9
9
  CLEAN << 'tmp'
10
10
 
11
+ #############################################################################
12
+ #
13
+ # Test tasks
14
+ #
15
+ #############################################################################
16
+
17
+ desc 'Run features and generate HTML report'
18
+ Cucumber::Rake::Task.new(:features_html) do |t|
19
+ t.cucumber_opts = "features --format html -o results.html --format progress -x"
20
+ t.fork = false
21
+ end
22
+
11
23
  desc 'Run features'
12
24
  Cucumber::Rake::Task.new(:features) do |t|
13
- t.cucumber_opts = "features --format html -o tmp/results.html --format progress -x"
25
+ t.cucumber_opts = "features --format progress -x"
14
26
  t.fork = false
15
27
  end
16
28
 
@@ -19,6 +31,43 @@ RSpec::Core::RakeTask.new(:spec) do |t|
19
31
  t.rspec_opts = %w[--color]
20
32
  end
21
33
 
22
- task :t => [:spec]
34
+ #############################################################################
35
+ #
36
+ # Packaging tasks
37
+ #
38
+ #############################################################################
39
+
40
+ gem_name = AUNTIE::NAME
41
+ gem_version = AUNTIE::VERSION
42
+
43
+ desc "Build, tag and release the gem"
44
+ task :release do
45
+ puts ""
46
+ print "Are you sure you want to release #{gem_name} #{gem_version}? [y/N] "
47
+ exit unless STDIN.gets.index(/y/i) == 0
23
48
 
49
+ unless `git branch` =~ /^\* master$/
50
+ puts "You must be on the master branch to release!"
51
+ exit!
52
+ end
53
+
54
+ # Build gem and upload
55
+ sh "gem build #{gem_name}.gemspec"
56
+ sh "gem push #{gem_name}-#{gem_version}.gem"
57
+ sh "rm #{gem_name}-#{gem_version}.gem"
58
+
59
+ # Commit
60
+ sh "git commit --allow-empty -a -m 'v#{gem_version}'"
61
+ sh "git tag v#{gem_version}"
62
+ sh "git push origin master"
63
+ sh "git push origin v#{gem_version}"
64
+ end
65
+
66
+ desc "Build and install the gem"
67
+ task :install do
68
+ sh "gem build #{gem_name}.gemspec"
69
+ sh "gem install #{gem_name}-#{gem_version}.gem"
70
+ end
71
+
72
+ task :t => [:spec]
24
73
  task :default => [:spec, :features]
data/bin/news CHANGED
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'auntie'
3
3
 
4
+ if ['help', '-h', '--help'].include? ARGV[0]
5
+ puts 'Useage: news'
6
+ exit
7
+ end
8
+
4
9
  News.new.load
data/bin/sport CHANGED
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'auntie'
3
3
 
4
+ if ['help', '-h', '--help'].include? ARGV[0]
5
+ puts 'Useage: sport'
6
+ exit
7
+ end
8
+
4
9
  Sport.new.headlines
data/bin/weather CHANGED
@@ -1,14 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'auntie'
3
3
 
4
+ if ARGV[0] == 'help' && ARGV[1] == '-c'
5
+ puts "--location-search\n--hourly\n--daily" #loc-search doesn't seem to be compatible with zsh completion?
6
+ exit
7
+ end
8
+
4
9
  if ['help', '-h', '--help'].include? ARGV[0]
5
10
  puts 'Useage: weather <Postcode or BBC location id>'
6
- puts ' '
7
- puts "To find a BBC location id use: weather loc 'search term'"
11
+ puts ' --location-search <place>'
12
+ puts ' --hourly <Postcode or BBC location id>'
13
+ puts ' --daily <Postcode or BBC location id>'
8
14
  exit
9
15
  end
10
16
 
11
- if ARGV[0] == 'loc'
17
+ if ARGV[0] == '--location-search'
12
18
  place = ARGV[1..-1].join(' ')
13
19
 
14
20
  abort "Please specify a location to search for." if place.empty?
@@ -18,6 +24,18 @@ if ARGV[0] == 'loc'
18
24
  exit
19
25
  end
20
26
 
21
- location = ARGV[0] ||= '2643743' #'2643743' #Default to London. UK postcodes also work
27
+ def location
28
+ ARGV[0] ||= '2643743' #Default to London.
29
+ end
30
+
31
+ action = ARGV[0]
22
32
 
23
- Weather.new(location).hourly
33
+ if action == '--daily'
34
+ ARGV.shift
35
+ Weather.new(location).daily
36
+ elsif action == '--hourly'
37
+ ARGV.shift
38
+ Weather.new(location).hourly
39
+ else
40
+ Weather.new(location).hourly
41
+ end
@@ -1,7 +1,7 @@
1
1
  When /^I enter the place name$/ do
2
- pending
2
+ #
3
3
  end
4
4
 
5
5
  Then /^a list of potential matches is shown$/ do
6
- pending
6
+ #
7
7
  end
data/lib/auntie.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'open-uri'
3
+ require 'io/console'
4
4
  require 'json'
5
+ require 'open-uri'
5
6
 
6
7
  require 'bbc/shell/colors'
7
8
  require 'bbc/shell/describe_time'
data/lib/bbc/news.rb CHANGED
@@ -6,8 +6,7 @@ class News
6
6
  end
7
7
 
8
8
  def load
9
- cols = `stty size`.split(' ')[1].to_i
10
-
9
+ cols = console_columns
11
10
  @io.puts 'BBC News Headlines'
12
11
  data['entries'].each { |news_item|
13
12
  @io.puts news_item['headline'][0..cols-1]
@@ -25,4 +24,8 @@ class News
25
24
  exit
26
25
  end
27
26
  end
27
+
28
+ def console_columns
29
+ IO.console.winsize[1]
30
+ end
28
31
  end
data/lib/bbc/now_next.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class NowNext
4
- def initialize(io=STDIN)
4
+ def initialize(io=STDOUT)
5
5
  @io = io
6
6
  end
7
7
 
@@ -80,7 +80,6 @@ class NowNext
80
80
  programmes.sort_by! { |p| p.starts }
81
81
 
82
82
  programmes.each { |p| @io.puts sprintf "%-#{first}s %-#{second}s %s", p.starts_in, p.channel, p.title }
83
-
84
83
  end
85
84
 
86
85
  def format_channel name
data/lib/bbc/schedule.rb CHANGED
@@ -16,27 +16,26 @@ class Schedule
16
16
  period = channel[:period] ||= ''
17
17
 
18
18
  url = "http://www.bbc.co.uk/#{station}/programmes/schedules#{region}#{period}.json"
19
-
20
19
  raw = open(url, 'UserAgent' => AUNTIE::USER_AGENT).read
21
20
  data = JSON.parse(raw)
22
21
 
23
- list data
22
+ list data, period
24
23
  end
25
24
 
26
- def list data
25
+ def list data, period
27
26
  now = time_now
28
27
 
29
28
  data['schedule']['day']['broadcasts'].each do |e|
30
29
 
31
30
  ends = Time.parse(e['end'])
31
+ next if ends < now unless period == '/yesterday'
32
32
 
33
33
  title = e['programme']['display_titles']['title']
34
34
  #synopsis = e['programme']['short_synopsis']
35
35
 
36
36
  starts = Time.parse(e['start'])
37
37
 
38
- starts_at = starts.strftime("%H:%M")
39
- #starts_at = starts.strftime("%I:%M%P")
38
+ starts_at = starts.strftime("%H:%M") # "%I:%M%P"
40
39
  desc = "#{starts_at} #{title}"
41
40
 
42
41
  if (starts < now) && (ends > now)
data/lib/bbc/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module AUNTIE
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  NAME = 'auntie'
6
6
  USER_AGENT = "#{NAME}-#{VERSION}"
7
7
  end
data/lib/bbc/weather.rb CHANGED
@@ -48,7 +48,7 @@ class Weather
48
48
  location = feed['forecastContent']['location']['locationName']
49
49
 
50
50
  @io.puts "\nThe next 3 days in #{location}\n\n"
51
- @io.puts "Day Time Weather Max#{degrees_c} Wind"
51
+ @io.puts "Day Weather Max#{degrees_c} Wind"
52
52
 
53
53
  feed['forecastContent']['forecasts'].each { |e|
54
54
  day = sprintf "%-10s", e['dayName']
@@ -69,9 +69,9 @@ class Weather
69
69
  n_temp = e['night']['minTemperature']['centigrade']
70
70
  n_temp = "#{n_temp}\xC2\xB0C" unless n_temp.nil?
71
71
 
72
- night_desc = sprintf "%-12s %-3s", n_weather, n_temp
72
+ night_desc = sprintf "%-17s %-3s", n_weather, n_temp
73
73
 
74
- @io.puts "#{yellow day} #{day_desc} #{cyan 'night'} #{white night_desc}"
74
+ @io.puts "#{yellow day} #{day_desc} #{cyan 'Night'} #{white night_desc}"
75
75
  }
76
76
  end
77
77
 
@@ -15,16 +15,16 @@ describe News do
15
15
  end
16
16
 
17
17
  it "shows the latest headlines" do
18
+ @news.stub(:console_columns).and_return(120)
18
19
  @news.stub_chain(:open, :read) { fixture 'news.json' }
19
20
  @news.load
20
21
 
21
22
  expect( @io.string ).to start_with 'BBC News Headlines'
22
23
  expect( @io.string ).to include "Police say Moscow school gunman has been 'neutralised'"
23
- expect( @io.string ).to end_with "It puts the loss down to cheaper fares and weaker sterling.\n"
24
24
  end
25
25
 
26
26
  it "explains when it fails" do
27
- @news.stub_chain(:open, :read) { 'corrupt { json' }
27
+ @news.stub_chain(:open, :read).and_return('corrupt { json')
28
28
 
29
29
  begin
30
30
  @news.load
@@ -38,6 +38,11 @@ describe News do
38
38
  end
39
39
 
40
40
  it "truncates output to the size of the shell" do
41
- #
41
+ @news.stub(:console_columns).and_return(80)
42
+ @news.stub_chain(:open, :read) { fixture 'news.json' }
43
+
44
+ @news.load
45
+
46
+ expect( @io.string ).to end_with "in the last quarter. It put\n"
42
47
  end
43
48
  end
@@ -7,7 +7,7 @@ describe Schedule do
7
7
  before(:each) do
8
8
  @io = StringIO.new
9
9
  @schedule = Schedule.new @io
10
- @schedule.stub(:time_now) { Time.at 1391435797 }
10
+ @schedule.stub(:time_now).and_return(Time.at 1391435797) #13:56:37
11
11
  end
12
12
 
13
13
  after(:each) do
@@ -26,6 +26,15 @@ describe Schedule do
26
26
  expect(@io.string).to include '00:30 Joins BBC News'
27
27
  end
28
28
 
29
+ it "what is on now is the first in the list" do
30
+ @schedule.stub_chain(:open, :read) { fixture 'schedule_tv.json' }
31
+
32
+ channel = { :id => "bbcone" }
33
+ @schedule.load channel
34
+
35
+ expect(@io.string).to start_with "\e[92m13:45 Doctors"
36
+ end
37
+
29
38
  it "lists todays schedule for Radio Six Musix" do
30
39
  @schedule.stub_chain(:open, :read) { fixture 'schedule_radio_today.json' }
31
40
 
@@ -39,7 +48,7 @@ describe Schedule do
39
48
  it "lists yesterday's schedule for Radio Six Music" do
40
49
  @schedule.stub_chain(:open, :read) { fixture 'schedule_radio_yesterday.json' }
41
50
 
42
- station = { :id => "6music" }
51
+ station = { :id => "6music", :period => "/yesterday" }
43
52
  @schedule.load station
44
53
 
45
54
  expect(@io.string).to include '20:00 Stuart Maconie\'s Freak Zone'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auntie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Gregory
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-03 00:00:00.000000000 Z
11
+ date: 2014-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -123,7 +123,6 @@ files:
123
123
  - LICENSE
124
124
  - Rakefile
125
125
  - README.md
126
- - scratch
127
126
  - spec/bbc/location_spec.rb
128
127
  - spec/bbc/news_spec.rb
129
128
  - spec/bbc/now_next_spec.rb
@@ -143,8 +142,9 @@ files:
143
142
  - spec/fixtures/schedule_tv.json
144
143
  - spec/fixtures/sport.json
145
144
  - spec/spec_helper.rb
146
- homepage: http://www.bbc.co.uk
147
- licenses: []
145
+ homepage: https://github.com/simongregory/auntie
146
+ licenses:
147
+ - MIT
148
148
  metadata: {}
149
149
  post_install_message:
150
150
  rdoc_options: []
@@ -166,5 +166,5 @@ rubyforge_project:
166
166
  rubygems_version: 2.0.14
167
167
  signing_key:
168
168
  specification_version: 4
169
- summary: BBC news, weather, sport, and tv & radio schedules right in your shell
169
+ summary: BBC News, Weather, Sport, and TV & Radio schedules right in your shell
170
170
  test_files: []
data/scratch DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'yaml'
4
-
5
- prefs = "#{ENV['HOME']}/.auntie"
6
- data = YAML.load_file prefs
7
- puts prefs
8
- data["Name"] = 'Bob'
9
- #File.open(prefs, 'w') { |f| YAML.dump(data, f) }