Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 20 commits
  • 8 files changed
  • 0 comments
  • 1 contributor
4 .gitignore
... ... @@ -0,0 +1,4 @@
  1 +*.sh
  2 +*.gem
  3 +*.swp
  4 +*.swo
5 bin/score_watch
... ... @@ -0,0 +1,5 @@
  1 +#!/usr/bin/ruby
  2 +
  3 +require File.dirname(__FILE__) + '/../lib/ScoreWatch'
  4 +
  5 +ScoreWatch::Match.new ARGV[0]
BIN  lib/.ScoreWatch.rb.swp
Binary file not shown
10 lib/ScoreWatch.rb
... ... @@ -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'
BIN  lib/ScoreWatch/.match.rb.swp
Binary file not shown
125 lib/ScoreWatch/match.rb
... ... @@ -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
14 score_watch.gemspec
... ... @@ -0,0 +1,14 @@
  1 +require 'lib/ScoreWatch'
  2 +
  3 +Gem::Specification.new do |s|
  4 + s.name = 'ScoreWatch'
  5 + s.version = ScoreWatch::VERSION
  6 + s.summary = 'Watches ESPN Gamecast pages for updates and broadcasts those updates.'
  7 + s.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.'
  8 + s.authors = ["Chris Svenningsen"]
  9 + s.email = 'crsven@gmail.com'
  10 + s.executables = ["score_watch"]
  11 + s.files = Dir["{lib}/**/*", "[A-Z]*"] - ["Gemfile.lock"]
  12 + s.homepage = 'http://www.crsvenningsen.com/projects'
  13 + s.require_path = 'lib'
  14 +end
76 score_watch.rb
... ... @@ -1,76 +0,0 @@
1   -#!/usr/bin/ruby
2   -
3   -require 'open-uri'
4   -require 'nokogiri'
5   -
6   -url = "http://soccernet.espn.go.com/gamecast?id="
7   -game = ARGV[0]
8   -url+=game
9   -
10   -old_score = "0 - 0"
11   -
12   -html = Nokogiri::HTML(open(url))
13   -home_team = html.css(".team.home h3").first.content
14   -away_team = html.css(".team.away h3").first.content
15   -
16   -# If not started, wait to announce start
17   -started = FALSE
18   -waiting = FALSE
19   -while started == FALSE do
20   - clock = html.css("##{game.to_s}clock").first
21   - if clock['style'].include?("display:none") && waiting == FALSE
22   - puts "Waiting for match to start..."
23   - waiting = TRUE
24   - sleep 30
25   - elsif clock['style'].include?("display:none") && waiting == TRUE
26   - sleep 30
27   - else
28   - start_message = "Match has started: #{home_team} v #{away_team}"
29   - puts start_message
30   - growl_input = "-n 'Gamecast' -m '#{start_message}'"
31   - system("growlnotify #{growl_input}")
32   - started = TRUE
33   - waiting = FALSE
34   - game_on = TRUE
35   - end
36   -end
37   -
38   -while game_on == TRUE do
39   - # Open gamecast page
40   - html = Nokogiri::HTML(open(url))
41   -
42   - # Check status of match
43   - timeStatus = html.css("##{game.to_s}statusTabText").first.content
44   - timeStatus.strip!
45   - # If Full Time, end watcher
46   - if timeStatus == "Full-time"
47   - game_on = FALSE
48   - puts "All over!"
49   - growl_input = "-n 'Gamecast' -m 'Game over!'"
50   - system("growlnotify #{growl_input}")
51   - exit
52   - end
53   -
54   - time = html.css("##{game.to_s}clock").first.content
55   - time = time.gsub(" ","").gsub("-","").gsub("'","")
56   -
57   - scoreline = html.css(".matchup-score").first.content
58   - scoreline.gsub("?","")
59   - if scoreline != old_score
60   - puts "#{time}': #{home_team} #{scoreline} #{away_team}"
61   - growl_input = "-n 'Gamecast' -m '#{home_team} v. #{away_team} #{time}':\nScore was #{old_score}, but is now #{scoreline}'"
62   - system("growlnotify #{growl_input}")
63   - old_score = scoreline
64   - goal_comment = html.css(".select-comment").first
65   - goal_text = ""
66   - if goal_comment
67   - goal_comment.css("b").each do |text|
68   - goal_text+=text.content
69   - end
70   - puts "#{goal_text}\n"
71   - growl_input = "-n 'Gamecast' -m '#{goal_text}'"
72   - system("growlnotify #{growl_input}")
73   - end
74   - end
75   - sleep 30
76   -end

No commit comments for this range

Something went wrong with that request. Please try again.