sports_db 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/article.rb +33 -0
- data/app/models/conference.rb +11 -0
- data/app/models/external_feed.rb +4 -0
- data/app/models/game_starting_player.rb +4 -0
- data/app/models/game_stat.rb +2 -0
- data/app/models/injury_report.rb +3 -0
- data/app/models/leaderboard.rb +3 -0
- data/app/models/news_filter.rb +7 -0
- data/app/models/notification.rb +4 -0
- data/app/models/participant.rb +7 -0
- data/app/models/period.rb +3 -0
- data/app/models/play.rb +6 -0
- data/app/models/player.rb +26 -0
- data/app/models/player_stat.rb +4 -0
- data/app/models/poll_ranking.rb +3 -0
- data/app/models/score.rb +2 -0
- data/lib/sports_db/external_feed_builder.rb +60 -0
- data/lib/sports_db/news_filters_builder.rb +84 -0
- data/lib/sports_db/version.rb +1 -1
- data/lib/sports_db.rb +3 -1
- metadata +20 -2
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
|
3
|
+
class Article < ActiveRecord::Base
|
4
|
+
belongs_to :player
|
5
|
+
belongs_to :game
|
6
|
+
has_and_belongs_to_many :news_filters, :join_table => "articles_news_filters"
|
7
|
+
|
8
|
+
def self.find_by_category(category)
|
9
|
+
Article.find(:all, :conditions => ['category = ?', category], :order => 'published_at DESC')
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_digest
|
13
|
+
str = (self["published_at"].nil?) ? self["title"] : (self["title"] + self["published_at"].to_s)
|
14
|
+
self["digest"] = Digest::SHA1.hexdigest(str)
|
15
|
+
end
|
16
|
+
|
17
|
+
def is_article?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def is_video?
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
def is_twitter?
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
def sn_url
|
30
|
+
self["link"]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Conference < ActiveRecord::Base
|
2
|
+
has_many :teams
|
3
|
+
|
4
|
+
def self.div_1a
|
5
|
+
self.find(:all, :conditions => { :league => "NCAA Men's Football Division 1A" }, :order => "name")
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.div_1aa
|
9
|
+
self.find(:all, :conditions => { :league => "NCAA Men's Football Division 1AA" }, :order => "name")
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class NewsFilter < ActiveRecord::Base
|
2
|
+
|
3
|
+
# Having additional attributes on the join table of a has_and_belongs_to_many association is deprecated and will be removed in Rails 3.1. Please use a has_many :through association instead
|
4
|
+
has_and_belongs_to_many :articles, :join_table => "articles_news_filters", :order => 'published_at DESC'
|
5
|
+
|
6
|
+
end
|
7
|
+
|
data/app/models/play.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
class Player < ActiveRecord::Base
|
2
|
+
has_one :article
|
3
|
+
has_many :player_stats
|
4
|
+
belongs_to :team
|
5
|
+
has_one :injury_report
|
6
|
+
|
7
|
+
def self.find_by_last_comma_first(full_name)
|
8
|
+
tokens = full_name.split(',')
|
9
|
+
Player.all(:conditions => ['last_name = ? and first_name = ?', tokens[0].strip, tokens[1].strip])
|
10
|
+
end
|
11
|
+
|
12
|
+
def year_abbreviation()
|
13
|
+
if self.eligibility.nil?
|
14
|
+
""
|
15
|
+
elsif self.eligibility == "Freshman"
|
16
|
+
"Fr"
|
17
|
+
elsif self.eligibility == "Sophomore"
|
18
|
+
"So"
|
19
|
+
elsif self.eligibility == "Junior"
|
20
|
+
"Jr"
|
21
|
+
elsif self.eligibility == "Senior"
|
22
|
+
"Sr"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/app/models/score.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module SportsDb
|
2
|
+
class ExternalFeedBuilder
|
3
|
+
|
4
|
+
def self.update_external_feeds
|
5
|
+
Rails.logger.info('updating team external feeds')
|
6
|
+
|
7
|
+
count = 0
|
8
|
+
|
9
|
+
open( SimpleConfig.for(:feeds).team_feeds_xml ) do |file|
|
10
|
+
doc = Nokogiri::XML(file.read)
|
11
|
+
doc.xpath('//team').each do |team_node|
|
12
|
+
team_obj = Team.find_by_key(team_node.xpath("key").first.text)
|
13
|
+
|
14
|
+
if !team_obj.blank?
|
15
|
+
external_twitter_url = team_node.xpath("sn_twitter_feed").first.text
|
16
|
+
woven_twitter_url = team_node.xpath("woven_twitter_feed").first.text
|
17
|
+
store_feed(external_twitter_url, woven_twitter_url, "twitter", "Sporting News", team_obj.id)
|
18
|
+
|
19
|
+
external_news_url = team_node.xpath("sn_news_feed").first.text
|
20
|
+
woven_news_url = team_node.xpath("woven_news_feed").first.text
|
21
|
+
store_feed(external_news_url, woven_news_url, "news", "Sporting News", team_obj.id)
|
22
|
+
|
23
|
+
count += 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
p "Processed #{count} teams"
|
27
|
+
end
|
28
|
+
|
29
|
+
rescue Exception => e
|
30
|
+
Zumobi::ExceptionHandler.error e
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def self.store_feed(external_url, woven_url, content_type, source, team_id)
|
35
|
+
if !external_url.blank? && !woven_url.blank?
|
36
|
+
|
37
|
+
feed = ExternalFeed.find(:first, :conditions => ["team_id = ? and content_type = ? and provider = ?", team_id, content_type, source])
|
38
|
+
if feed.blank?
|
39
|
+
ExternalFeed.create({
|
40
|
+
:team_id => team_id,
|
41
|
+
:feed_source_url => external_url,
|
42
|
+
:woven_feed_url => woven_url,
|
43
|
+
:provider => source,
|
44
|
+
:content_type => content_type
|
45
|
+
})
|
46
|
+
else
|
47
|
+
feed.update_attributes({
|
48
|
+
:team_id => team_id,
|
49
|
+
:feed_source_url => external_url,
|
50
|
+
:woven_feed_url => woven_url,
|
51
|
+
:provider => source,
|
52
|
+
:content_type => content_type
|
53
|
+
})
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module SportsDb
|
2
|
+
class NewsFilterBuilder
|
3
|
+
|
4
|
+
def self.update_news_filters(league=nil)
|
5
|
+
p "updating news filters, league=#{league}"
|
6
|
+
|
7
|
+
add_static_filters
|
8
|
+
|
9
|
+
if league == 'mlb'
|
10
|
+
add_team_filters
|
11
|
+
add_mlb_league_filters
|
12
|
+
elsif league == 'nba'
|
13
|
+
add_team_filters
|
14
|
+
add_nba_league_filters
|
15
|
+
elsif league == 'nfl'
|
16
|
+
add_team_filters
|
17
|
+
add_nfl_league_filters
|
18
|
+
elsif league == 'ncaabb'
|
19
|
+
add_team_filters
|
20
|
+
add_ncaa_conferences_filters
|
21
|
+
elsif league == 'ncaafb'
|
22
|
+
add_fbs_only_team_filters
|
23
|
+
add_ncaa_conferences_filters
|
24
|
+
end
|
25
|
+
rescue Exception => e
|
26
|
+
Zumobi::ExceptionHandler.error e
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def self.add_static_filters
|
31
|
+
update_create_news_filter('All', 'all')
|
32
|
+
update_create_news_filter(CONFIG.affiliation_name, CONFIG.affiliation_key)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.add_mlb_league_filters
|
36
|
+
update_create_news_filter('American League', 'American')
|
37
|
+
update_create_news_filter('National League', 'National')
|
38
|
+
update_create_news_filter('Fantasy', 'fantasy')
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.add_nba_league_filters
|
42
|
+
update_create_news_filter('Eastern', 'Eastern')
|
43
|
+
update_create_news_filter('Western', 'Western')
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.add_nfl_league_filters
|
47
|
+
update_create_news_filter('American', 'American')
|
48
|
+
update_create_news_filter('National', 'National')
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.add_team_filters
|
52
|
+
teams = Team.find(:all)
|
53
|
+
teams.each do |team|
|
54
|
+
update_create_news_filter(team.city_name, team.key)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.add_fbs_only_team_filters
|
59
|
+
teams = Team.find(:all)
|
60
|
+
teams.each do |team|
|
61
|
+
if team.is_FBS?
|
62
|
+
update_create_news_filter(team.city_name, team.key)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.add_ncaa_conferences_filters
|
68
|
+
conferences = Conference.find(:all)
|
69
|
+
conferences.each do |conf|
|
70
|
+
update_create_news_filter(conf.abbreviation, conf.key)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.update_create_news_filter(filter_name, filter_key)
|
75
|
+
if NewsFilter.find(:first, :conditions => ['news_filter_key = ?', filter_key]).nil?
|
76
|
+
NewsFilter.create(
|
77
|
+
:name => filter_name,
|
78
|
+
:news_filter_key => filter_key
|
79
|
+
)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
data/lib/sports_db/version.rb
CHANGED
data/lib/sports_db.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Alx Dark
|
@@ -54,11 +54,29 @@ extra_rdoc_files: []
|
|
54
54
|
|
55
55
|
files:
|
56
56
|
- app/controllers/foo_controller.rb
|
57
|
+
- app/models/article.rb
|
58
|
+
- app/models/conference.rb
|
59
|
+
- app/models/external_feed.rb
|
60
|
+
- app/models/game_starting_player.rb
|
61
|
+
- app/models/game_stat.rb
|
62
|
+
- app/models/injury_report.rb
|
63
|
+
- app/models/leaderboard.rb
|
57
64
|
- app/models/media.rb
|
65
|
+
- app/models/news_filter.rb
|
66
|
+
- app/models/notification.rb
|
67
|
+
- app/models/participant.rb
|
68
|
+
- app/models/period.rb
|
69
|
+
- app/models/play.rb
|
70
|
+
- app/models/player.rb
|
71
|
+
- app/models/player_stat.rb
|
72
|
+
- app/models/poll_ranking.rb
|
73
|
+
- app/models/score.rb
|
58
74
|
- app/models/twitter.rb
|
59
75
|
- config/routes.rb
|
60
76
|
- lib/sports_db/engine.rb
|
77
|
+
- lib/sports_db/external_feed_builder.rb
|
61
78
|
- lib/sports_db/media_builder.rb
|
79
|
+
- lib/sports_db/news_filters_builder.rb
|
62
80
|
- lib/sports_db/twitter_builder.rb
|
63
81
|
- lib/sports_db/version.rb
|
64
82
|
- lib/sports_db.rb
|