series_timer 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +71 -0
- data/bin/series_timer +16 -0
- data/cache/empty +0 -0
- data/lib/series_timer/crawler.rb +51 -0
- data/lib/series_timer/episode.rb +25 -0
- data/lib/series_timer/errors.rb +4 -0
- data/lib/series_timer/series_manager.rb +31 -0
- data/lib/series_timer/version.rb +3 -0
- data/lib/series_timer.rb +36 -0
- metadata +55 -0
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Series Timer
|
2
|
+
|
3
|
+
scrapes the list of episodes of any series from wikipedia (i.e. http://en.wikipedia.org/wiki/List_of_House_episodes)
|
4
|
+
|
5
|
+
# Usage
|
6
|
+
|
7
|
+
````./bin/seriestimr -[lac] <series names>````
|
8
|
+
|
9
|
+
- -l = last episode on air
|
10
|
+
|
11
|
+
- -a = list all episodes
|
12
|
+
|
13
|
+
- -c = countdown to the next episode
|
14
|
+
|
15
|
+
ex:
|
16
|
+
````./bin/seriestimr -c House "The Big Bang Theory" "Dexter"````
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
## Countdown
|
21
|
+
|
22
|
+
````
|
23
|
+
./bin/series_timer -c "The Mentalist" Californication
|
24
|
+
[The Mentalist] S05e13 Red is the New Black 2012-02-02 (4 days)
|
25
|
+
[Californication] S05e04 Waiting for the Miracle 2012-01-29 (0 days)
|
26
|
+
````
|
27
|
+
|
28
|
+
|
29
|
+
## Last episode on air
|
30
|
+
|
31
|
+
````
|
32
|
+
./bin/series_timer -l House Dexter
|
33
|
+
[House] S09e09 Better Half 2012-01-23
|
34
|
+
[Dexter] S06e12 This Is the Way the World Ends 2011-12-18
|
35
|
+
````
|
36
|
+
|
37
|
+
## All Episodes
|
38
|
+
|
39
|
+
````
|
40
|
+
./bin/series_timer -a "Game of Thrones"
|
41
|
+
[Game of Thrones] S01e01 Winter Is Coming 2011-04-17
|
42
|
+
[Game of Thrones] S01e02 The Kingsroad 2011-04-24
|
43
|
+
[Game of Thrones] S01e03 Lord Snow 2011-05-01
|
44
|
+
[Game of Thrones] S01e04 Cripples 2011-05-08
|
45
|
+
[Game of Thrones] S01e05 The Wolf and the Lion 2011-05-15
|
46
|
+
[Game of Thrones] S01e06 A Golden Crown 2011-05-22
|
47
|
+
[Game of Thrones] S01e07 You Win or You Die 2011-05-29
|
48
|
+
[Game of Thrones] S01e08 The Pointy End 2011-06-05
|
49
|
+
[Game of Thrones] S01e09 Baelor 2011-06-12
|
50
|
+
[Game of Thrones] S01e10 Fire and Blood 2011-06-19
|
51
|
+
[Game of Thrones] S10e09 Blackwater 2012-05-27
|
52
|
+
````
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
## Authorship
|
58
|
+
|
59
|
+
Written by [Adriano Bacha](http://github.com/abacha) for Mendicant University's [University-Web](https://github.com/mendicant-university/university-web).
|
60
|
+
|
61
|
+
## License
|
62
|
+
|
63
|
+
Copyright (c) 2012 Adriano Bacha
|
64
|
+
|
65
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
66
|
+
|
67
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
68
|
+
|
69
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
70
|
+
|
71
|
+
---
|
data/bin/series_timer
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'net/http'
|
5
|
+
require 'json'
|
6
|
+
require 'date'
|
7
|
+
require "optparse"
|
8
|
+
require_relative '../lib/series_timer'
|
9
|
+
|
10
|
+
begin
|
11
|
+
SeriesTimer::Application.new(ARGV).run
|
12
|
+
rescue OptionParser::InvalidOption => err
|
13
|
+
abort "series_timer: #{err.message}\nusage: series_timer [-lac] [serie1 serie2 ...]"
|
14
|
+
rescue SeriesTimer::InvalidSerieException
|
15
|
+
abort "series_timer: invalid serie"
|
16
|
+
end
|
data/cache/empty
ADDED
File without changes
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative 'episode'
|
2
|
+
|
3
|
+
module SeriesTimer
|
4
|
+
module Crawler
|
5
|
+
class << self
|
6
|
+
|
7
|
+
REGEX_EPISODES =
|
8
|
+
Regexp.new(/<td>(\d+)<\/td>.*?<td class="summary" [^>]+>(?:"<b>)?(?:<a [^>]+>)?([\w\s]*)(?:<\/a>)?(?:<\/b>")?.*?<span[^>]+>([0-9-]+)<\/span>/m)
|
9
|
+
|
10
|
+
def get_episodes(serie)
|
11
|
+
File.exists?(get_cache_file(serie)) ? cache(serie) : web(serie)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def parse_episodes(serie, html)
|
16
|
+
episodes = []
|
17
|
+
html.scan(REGEX_EPISODES) { |episode| episodes << episode }
|
18
|
+
episodes
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_cache_file(serie)
|
22
|
+
File.join(File.dirname(__FILE__), "../../cache/") + serie + ".cache"
|
23
|
+
end
|
24
|
+
|
25
|
+
def web(serie)
|
26
|
+
renamed_serie = serie.gsub(" ", "_")
|
27
|
+
uri = URI("http://en.wikipedia.org/wiki/List_of_#{renamed_serie}_episodes")
|
28
|
+
response = Net::HTTP.get_response(uri)
|
29
|
+
raise InvalidSerieException if response.code == "404"
|
30
|
+
|
31
|
+
episodes = parse_episodes(serie, response.body)
|
32
|
+
File.open(get_cache_file(serie), 'w') { |file| file.write(episodes) }
|
33
|
+
cache(serie)
|
34
|
+
end
|
35
|
+
|
36
|
+
def cache(serie)
|
37
|
+
episodes_parsed = JSON.parse(File.open(get_cache_file(serie), "r").read)
|
38
|
+
season = 1
|
39
|
+
episodes = []
|
40
|
+
|
41
|
+
episodes_parsed.each do |episode|
|
42
|
+
season += 1 if !episodes.empty? &&
|
43
|
+
episodes.last.number > episode[0].to_i
|
44
|
+
episodes << Episode.new(serie, season.to_i, *episode) unless episode[1].empty?
|
45
|
+
end
|
46
|
+
episodes
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SeriesTimer
|
2
|
+
class Episode < Struct.new(:serie, :season, :number_raw, :title, :date_raw)
|
3
|
+
|
4
|
+
def date
|
5
|
+
@date ||= Date.parse date_raw
|
6
|
+
end
|
7
|
+
|
8
|
+
def countdown
|
9
|
+
"#{(date - Date.today).to_i} days"
|
10
|
+
end
|
11
|
+
|
12
|
+
def number
|
13
|
+
@number ||= number_raw.to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
def empty?
|
17
|
+
number_raw.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"[#{serie}] S%02de%02d\t #{title}\t #{date}" % [ season, number ]
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'crawler'
|
2
|
+
|
3
|
+
module SeriesTimer
|
4
|
+
module SeriesManager
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def countdown(serie)
|
8
|
+
episode = get_next_episode(serie)
|
9
|
+
return if episode.nil?
|
10
|
+
"#{episode.to_s} (#{episode.countdown})"
|
11
|
+
end
|
12
|
+
|
13
|
+
def last_episode(serie)
|
14
|
+
episodes = Crawler.get_episodes(serie)
|
15
|
+
episodes.reject! { |episode| episode.date >= Date.today }
|
16
|
+
episodes.last
|
17
|
+
end
|
18
|
+
|
19
|
+
def all(serie)
|
20
|
+
Crawler.get_episodes(serie)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def get_next_episode(serie)
|
25
|
+
episodes = Crawler.get_episodes(serie)
|
26
|
+
next_episode = episodes.find { |episode| episode.date >= Date.today }
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/series_timer.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative '../lib/series_timer/series_manager'
|
2
|
+
require_relative '../lib/series_timer/errors'
|
3
|
+
|
4
|
+
module SeriesTimer
|
5
|
+
class Application
|
6
|
+
|
7
|
+
def initialize(argv)
|
8
|
+
@params, @series = parse_options(argv)
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_options(argv)
|
12
|
+
params = {}
|
13
|
+
parser = OptionParser.new
|
14
|
+
parser.on("-c") { params[:episodes] = :countdown }
|
15
|
+
parser.on("-l") { params[:episodes] = :last }
|
16
|
+
parser.on("-a") { params[:episodes] = :all }
|
17
|
+
series = parser.parse(argv)
|
18
|
+
[params, series]
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
@series.each do |serie|
|
23
|
+
case @params[:episodes]
|
24
|
+
when :last
|
25
|
+
puts SeriesManager.last_episode(serie)
|
26
|
+
when :all
|
27
|
+
puts SeriesManager.all(serie)
|
28
|
+
else
|
29
|
+
puts SeriesManager.countdown(serie)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: series_timer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adriano Bacha
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-29 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: scrapes the list of episodes of any series from wikipedia
|
15
|
+
email:
|
16
|
+
- abacha@gmail.com
|
17
|
+
executables:
|
18
|
+
- series_timer
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- bin/series_timer
|
23
|
+
- lib/series_timer/errors.rb
|
24
|
+
- lib/series_timer/version.rb
|
25
|
+
- lib/series_timer/crawler.rb
|
26
|
+
- lib/series_timer/series_manager.rb
|
27
|
+
- lib/series_timer/episode.rb
|
28
|
+
- lib/series_timer.rb
|
29
|
+
- cache/empty
|
30
|
+
- README.md
|
31
|
+
homepage: http://github.com/series_timer
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.9.2
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.3.6
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project: series_timer
|
51
|
+
rubygems_version: 1.8.15
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: scrapes the list of episodes of any series from wikipedia
|
55
|
+
test_files: []
|