ScoreWatch 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ # Score Watch (until a better name comes to me)
2
+
3
+ ### Description
4
+ Takes an ESPN Gamecast match ID and scrapes the Gamecast page repeatedly to gather score updates. These are output on the command line and also in Growl (currently via [growlnotify](http://growl.info/extras.php#growlnotify))
5
+
6
+ ### TODO
7
+ * Stop using Growlnotify in favor of a Ruby growl library
8
+ * Allow for command line only
9
+ * Scrape a lower-density page for info, such as the day's list of games
10
+ * Allow for multiple games to be watched
11
+ * Add case for extra time
12
+ * Gem it up
Binary file
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/ScoreWatch'
4
+
5
+ ScoreWatch::Match.new ARGV[0]
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'open-uri'
4
+ require 'nokogiri'
5
+
6
+ module ScoreWatch
7
+ VERSION = "0.2"
8
+ end
9
+
10
+ require 'lib/ScoreWatch/match'
@@ -0,0 +1,125 @@
1
+ class ScoreWatch::Match
2
+ GROWL_OPTIONS = "-n 'Score Watch'"
3
+ PING_TIME = 30
4
+
5
+ def initialize(id)
6
+ @match_id = id
7
+ @match_url = "http://soccernet.espn.go.com/gamecast?id=#{@match_id}"
8
+ @current_time = nil
9
+ @old_score = "0 - 0"
10
+ @current_score = nil
11
+ @game_on = false
12
+ @status = nil
13
+ get_teams
14
+ watch
15
+ end
16
+
17
+ def watch
18
+ refresh
19
+ get_score
20
+ get_status
21
+ if @old_score != @current_score
22
+ message("#{@home_team} #{@current_score} #{@away_team}")
23
+ comment = get_goal_comment
24
+ if comment
25
+ message(comment)
26
+ end
27
+ end
28
+ wait
29
+ watch
30
+ end
31
+
32
+ private
33
+
34
+ def refresh
35
+ @html = Nokogiri::HTML(open(@match_url))
36
+ @current_time = get_current_time
37
+ end
38
+
39
+ def get_teams
40
+ refresh
41
+ @home_team = @html.css(".team.home h3").first.content
42
+ @away_team = @html.css(".team.away h3").first.content
43
+ end
44
+
45
+ def get_score
46
+ @old_score = @current_score
47
+ scoreline = @html.css(".matchup-score").first.content
48
+ scoreline.gsub("?","")
49
+ @current_score = scoreline
50
+ end
51
+
52
+ def get_goal_comment
53
+ refresh
54
+ goal_text = @html.css(".select-comment").first
55
+ goal_comment = ""
56
+ if goal_text
57
+ goal_comment = goal_text.css(".comment").first.content
58
+ end
59
+
60
+ if goal_comment.strip! == ""
61
+ return nil
62
+ end
63
+ end
64
+
65
+ def get_status
66
+ if @game_on == true
67
+ if is_over?
68
+ end_match
69
+ end
70
+ return
71
+ elsif is_started?
72
+ message("Match has started!")
73
+ @game_on = true
74
+ elsif is_over?
75
+ end_match
76
+ else
77
+ message("Waiting for match to start.")
78
+ end
79
+ end
80
+
81
+ def wait
82
+ sleep PING_TIME
83
+ end
84
+
85
+ def is_started?
86
+ refresh
87
+ clock = @html.css("##{@match_id.to_s}clock").first
88
+ if clock['style'].include?("display:none")
89
+ return false
90
+ else
91
+ return true
92
+ end
93
+ end
94
+
95
+ def get_current_time
96
+ clock = @html.css("##{@match_id.to_s}clock").first.content
97
+ time = clock.gsub(" ","").gsub("-","").gsub("'","")
98
+ end
99
+
100
+ def is_over?
101
+ refresh
102
+ timeStatus = @html.css("##{@match_id.to_s}statusTabText").first.content
103
+ timeStatus.strip!
104
+ if timeStatus == "Full-time"
105
+ return true
106
+ else
107
+ return false
108
+ end
109
+ end
110
+
111
+ def end_match
112
+ message("Match ended! Final score: #{@home_team} #{@current_score} #{@away_team}")
113
+ exit
114
+ end
115
+
116
+ def growl(text)
117
+ growl_input = "#{GROWL_OPTIONS} -m '#{text}'"
118
+ system("growlnotify #{growl_input}")
119
+ end
120
+
121
+ def message(text)
122
+ growl(text)
123
+ puts(text)
124
+ end
125
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ScoreWatch
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ version: "0.2"
10
+ platform: ruby
11
+ authors:
12
+ - Chris Svenningsen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-04-16 00:00:00 Z
18
+ dependencies: []
19
+
20
+ description: Given an ESPN Gamecast match ID, Score Watch will scrape the Gamecast Page for updates and broadcast them on the command line and also via GrowlNotify.
21
+ email: crsven@gmail.com
22
+ executables:
23
+ - score_watch
24
+ extensions: []
25
+
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - lib/ScoreWatch/match.rb
30
+ - lib/ScoreWatch.rb
31
+ - README.md
32
+ - Score_Watch-0.2.0.gem
33
+ - ScoreWatch-0.2.gem
34
+ - bin/score_watch
35
+ homepage: http://www.crsvenningsen.com/projects
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ hash: 3
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.8.15
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Watches ESPN Gamecast pages for updates and broadcasts those updates.
68
+ test_files: []
69
+