sports_db 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,61 +1,62 @@
1
1
  module SportsDb
2
- class TwitterBuilder
3
-
2
+ class TwitterBuilder
3
+
4
4
  def self.update_twitter
5
- new_tweets = []
6
-
7
- config = SimpleConfig.for(:feeds)
8
- config.twitter_feeds.each do |feed_title, url|
9
- parse_feed(new_tweets, url, feed_title)
10
- end
11
-
12
- Twitter.transaction do
5
+ new_tweets = []
6
+
7
+ config = SimpleConfig.for(:feeds)
8
+ config.twitter_feeds.each do |feed_title, url|
9
+ parse_feed(new_tweets, url, feed_title)
10
+ end
11
+
12
+ Twitter.transaction do
13
13
  Twitter.delete_all()
14
- new_tweets.each {|t| t.save}
15
- p "Tweets saved: #{new_tweets.length}"
16
- end
17
- end
18
-
19
- def self.update_ncaa_twitter
14
+ new_tweets.each {|t| t.save}
15
+ p "Tweets saved: #{new_tweets.length}"
16
+ end
17
+ end
18
+
19
+ def self.update_ncaa_twitter
20
20
  new_tweets = []
21
-
21
+
22
22
  config = SimpleConfig.for(:feeds)
23
- config.twitter_feeds.each do |feed_title, url|
23
+ config.twitter_feeds.each do |feed_title, url|
24
24
  parse_feed(new_tweets, url, feed_title)
25
25
  end
26
-
27
- ExternalFeed.find(:all, :conditions => ["content_type = ? and provider = ?", "twitter", "Sporting News"]).each do |feed_obj|
28
- feed_url = feed_obj.woven_feed_url
29
- if SimpleConfig.for(:application).woven_feed_server != "woven.zumobi.net"
30
- feed_url = feed_url.gsub("woven.zumobi.net", SimpleConfig.for(:application).woven_feed_server)
31
- end
32
-
33
- team_obj = Team.find(feed_obj.team_id)
34
- feed_name = (team_obj.nil? ? "Unknown" : team_obj.city_name)
35
- parse_feed(new_tweets, feed_url, feed_name, feed_obj.team_id)
26
+
27
+ ExternalFeed.find(:all, :conditions => ["content_type = ? and provider = ?", "twitter", "Sporting News"]).each do |feed_obj|
28
+ feed_url = feed_obj.woven_feed_url
29
+ if SimpleConfig.for(:application).woven_feed_server != "woven.zumobi.net"
30
+ feed_url = feed_url.gsub("woven.zumobi.net", SimpleConfig.for(:application).woven_feed_server)
31
+ end
32
+
33
+ team_obj = Team.find(feed_obj.team_id)
34
+ feed_name = (team_obj.nil? ? "Unknown" : team_obj.city_name)
35
+ parse_feed(new_tweets, feed_url, feed_name, feed_obj.team_id)
36
36
  end
37
-
37
+
38
38
  Twitter.transaction do
39
39
  Twitter.delete_all()
40
- new_tweets.each {|t| t.save}
41
- p "Tweets saved: #{new_tweets.length}"
42
- end
43
-
40
+ new_tweets.each {|t| t.save}
41
+ p "Tweets saved: #{new_tweets.length}"
42
+ end
43
+
44
44
  rescue Exception => e
45
45
  Zumobi::ExceptionHandler.error e
46
46
  end
47
47
 
48
48
 
49
- def self.parse_feed(new_tweets, url, feed_title, team_id=nil)
50
- require 'open-uri'
51
- p "Twitter - #{feed_title} - #{url}"
52
-
49
+ def self.parse_feed(new_tweets, url, feed_title, team_id=nil)
50
+ require 'open-uri'
51
+ p "Twitter - #{feed_title} - #{url}"
52
+
53
53
  begin
54
54
  open(url) do |file|
55
55
  doc = Nokogiri::XML(file.read)
56
56
  source = doc.xpath('/rss/channel/title').text
57
+ source = adjust_titles(source)
58
+ # this has to come after adjust_titles or it gomers it all up
57
59
  source = source.gsub('Twitter', '').strip
58
- source = title_changes(source)
59
60
 
60
61
  if !doc.nil? && !source.nil?
61
62
  doc.xpath('//item').each do |node|
@@ -71,15 +72,15 @@ class TwitterBuilder
71
72
  t.contents = t.title
72
73
 
73
74
  team_key = team_mapping(t.source)
74
-
75
- if !team_key.blank?
76
- if Team.column_names.include?("tsn_key") && !Team.find_by_tsn_key(team_key).blank?
77
- t.team_id = Team.find_by_tsn_key(team_key).id
78
- elsif !Team.find_by_key(team_key).blank?
79
- t.team_id = Team.find_by_key(team_key).id
80
- end
75
+
76
+ if !team_key.blank?
77
+ if Team.column_names.include?("tsn_key") && !Team.find_by_tsn_key(team_key).blank?
78
+ t.team_id = Team.find_by_tsn_key(team_key).id
79
+ elsif !Team.find_by_key(team_key).blank?
80
+ t.team_id = Team.find_by_key(team_key).id
81
+ end
81
82
  end
82
-
83
+
83
84
  new_tweets << t
84
85
  end
85
86
  end
@@ -87,34 +88,40 @@ class TwitterBuilder
87
88
  rescue OpenURI::HTTPError => http_e
88
89
  p 'unable to retrieve feed'
89
90
  rescue EOFError
90
- p 'connection error'
91
+ p 'connection error'
91
92
  rescue Errno::ECONNRESET
92
- p 'connection error'
93
+ p 'connection error'
93
94
  rescue Errno::ECONNREFUSED
94
- p 'connection error'
95
- end
95
+ p 'connection error'
96
+ end
96
97
  rescue Exception => e
97
98
  Zumobi::ExceptionHandler.error e
98
99
  end
99
100
 
100
- def self.title_changes(source)
101
- titles = {'Official NFL Twitter Feed' => 'NFL',
102
- 'The Trenches Twitter' => 'The Trenches'}
103
-
104
- return (titles[source].nil?) ? source : titles[source]
101
+ # Adjust the title for a couple of feeds.
102
+ # Return the original title if it doesn't
103
+ # need to be adjusted.
104
+ def self.adjust_titles(title)
105
+ if title == 'Official NFL Twitter Feed'
106
+ return 'NFL'
107
+ elsif title == 'The Trenches Twitter'
108
+ return 'The Trenches'
109
+ else
110
+ return title
111
+ end
105
112
  end
106
-
113
+
107
114
  def self.add_hash_highlight(str)
108
115
  formatted_text = []
109
116
  each_word = str.split(' ')
110
- each_word.each do |word|
117
+ each_word.each do |word|
111
118
  if word[0,7] == "http://"
112
119
  new_word = "<a href='#{word}'>#{word}</a>"
113
120
  formatted_text << new_word
114
121
  elsif word.include? "http://"
115
122
  phrase = word
116
123
  pieces = word.split("http://")
117
-
124
+
118
125
  phrase = "#{pieces[0]} <a href='http://#{pieces[1]}'>http://#{pieces[1]}</a>"
119
126
  formatted_text << phrase
120
127
  else
@@ -156,7 +163,7 @@ class TwitterBuilder
156
163
  'Carolina Panthers' => 'l.nfl.com-t.29',
157
164
  'New Orleans Saints' => 'l.nfl.com-t.30',
158
165
  'Tampa Bay Bucs' => 'l.nfl.com-t.26',
159
- 'Arizona Diamondbacks' => 'l.mlb.com-t.26',
166
+ 'Arizona Diamondbacks' => 'l.mlb.com-t.26',
160
167
  'Atlanta Braves' => 'l.mlb.com-t.15',
161
168
  'Baltimore Orioles' => 'l.mlb.com-t.1',
162
169
  'Boston Red Sox' => 'l.mlb.com-t.2',
@@ -168,7 +175,7 @@ class TwitterBuilder
168
175
  'Detroit Tigers' => 'l.mlb.com-t.8',
169
176
  'Miami Marlins' => 'l.mlb.com-t.16',
170
177
  'Houston Astros' => 'l.mlb.com-t.22',
171
- 'Kansas City Royals' => 'l.mlb.com-t.9',
178
+ 'Kansas City Royals' => 'l.mlb.com-t.9',
172
179
  'Los Angeles Angels' => 'l.mlb.com-t.11',
173
180
  'Los Angeles Dodgers' => 'l.mlb.com-t.28',
174
181
  'Milwaukee Brewers' => 'l.mlb.com-t.23',
@@ -177,7 +184,7 @@ class TwitterBuilder
177
184
  'New York Yankees' => 'l.mlb.com-t.3',
178
185
  'Oakland Athletics' => 'l.mlb.com-t.12',
179
186
  'Philadelphia Phillies' => 'l.mlb.com-t.19',
180
- 'Pittsburgh Pirates' => 'l.mlb.com-t.24',
187
+ 'Pittsburgh Pirates' => 'l.mlb.com-t.24',
181
188
  'San Diego Padres' => 'l.mlb.com-t.29',
182
189
  'San Francisco Giants' => 'l.mlb.com-t.30',
183
190
  'Seattle Mariners' => 'l.mlb.com-t.13',
@@ -186,7 +193,7 @@ class TwitterBuilder
186
193
  'Texas Rangers' => 'l.mlb.com-t.14',
187
194
  'Toronto Blue Jays' => 'l.mlb.com-t.5',
188
195
  'Washington Nationals' => 'l.mlb.com-t.17',
189
- 'Boston Celtics' => 'l.nba.com-t.1',
196
+ 'Boston Celtics' => 'l.nba.com-t.1',
190
197
  'Brooklyn Nets' => 'l.nba.com-t.3',
191
198
  'New York Knicks' => 'l.nba.com-t.4',
192
199
  'Philadelphia 76ers' => 'l.nba.com-t.6',
@@ -199,7 +206,7 @@ class TwitterBuilder
199
206
  'Atlanta Hawks' => 'l.nba.com-t.8',
200
207
  'Charlotte Bobcats' => 'l.nba.com-t.32',
201
208
  'Miami Heat' => 'l.nba.com-t.2',
202
- 'Orlando Magic' => 'l.nba.com-t.5',
209
+ 'Orlando Magic' => 'l.nba.com-t.5',
203
210
  'Washington Wizards' => 'l.nba.com-t.7',
204
211
  'Denver Nuggets' => 'l.nba.com-t.17',
205
212
  'Minnesota Timberwolves' => 'l.nba.com-t.20',
@@ -208,7 +215,7 @@ class TwitterBuilder
208
215
  'Utah Jazz' => 'l.nba.com-t.22',
209
216
  'Golden State Warriors' => 'l.nba.com-t.23',
210
217
  'Los Angeles Clippers' => 'l.nba.com-t.24',
211
- 'Los Angeles Lakers' => 'l.nba.com-t.25',
218
+ 'Los Angeles Lakers' => 'l.nba.com-t.25',
212
219
  'Phoenix Suns' => 'l.nba.com-t.26',
213
220
  'Sacramento Kings' => 'l.nba.com-t.28',
214
221
  'Dallas Mavericks' => 'l.nba.com-t.16',
@@ -221,4 +228,4 @@ class TwitterBuilder
221
228
  end
222
229
 
223
230
  end
224
- end
231
+ end
@@ -1,3 +1,3 @@
1
1
  module SportsDb
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sports_db
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alx Dark
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-05-20 00:00:00 -06:00
18
+ date: 2013-05-29 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency