PageRenderTime 31ms CodeModel.GetById 13ms app.highlight 17ms RepoModel.GetById 0ms app.codeStats 0ms

/db/migrations/201204262257_create_inter_gremio_flamengo_corinthians.rb

https://bitbucket.org/tbueno/planetafutebol
Ruby | 90 lines | 76 code | 13 blank | 1 comment | 2 complexity | 2875745ed6806ce0b51860caa78f93a9 MD5 | raw file
 1# encoding: UTF-8
 2
 3db = URI.parse(ENV['MONGOHQ_URL'])
 4db_name = db.path.gsub(/^\//, '')
 5
 6db_connection = Mongo::Connection.new(db.host, db.port).db(db_name)
 7db_connection.authenticate(db.user, db.password) unless (db.user.nil? || db.user.nil?)
 8
 9
10migrations = db_connection['migrations']
11if migrations.find_one({file: __FILE__})
12  puts "Skipping:  #{__FILE__}"
13else
14  puts "Migrating: #{__FILE__}"
15
16  CLUBS = [
17    { name: 'Internacional', 
18      website: 'http:///www.internacional.com.br',
19      twitter: 'SCInternacional',
20      sources: [
21        {name: 'ESPN', website: 'http://www.espn.com.br/rss/internacional', url: 'http://espn.estadao.com.br/rss/internacional'},
22        {name: 'Gazeta Esportiva', website: 'http://www.gazetaesportiva.net/canal/89/inter-rs/', url: 'http://www.gazetaesportiva.net/rss/89.xml'},
23        {name: 'Lancenet', website: 'http://www.lancenet.com.br/internacional/', url: 'http://www.lancenet.com.br/rss/internacional/'},
24        {name: 'Globoesporte', website: 'http://globoesporte.globo.com/futebol/times/internacional/', url: 'http://globoesporte.globo.com/dynamo/semantica/editorias/plantao/futebol/times/internacional/feed.rss'},
25        {name: 'Canelada', website: 'http://canelada.com.br/category/internacional/', url: 'http://feeds.feedburner.com/CaneladaInternacional'}
26      ] 
27    },
28    
29    {
30    name: 'GrĂªmio',
31    website: 'http://www.gremio.net',
32    twitter: 'gremiooficial',
33    sources: [
34        {name: 'ESPN', website: 'http://www.espn.com.br/rss/gremio', url: 'http://espn.estadao.com.br/rss/gremio'},
35        {name: 'Gazeta Esportiva', website: 'http://www.gazetaesportiva.net/canal/22/gremio/', url: 'http://www.gazetaesportiva.net/rss/22.xml'},
36        {name: 'Lancenet', website: 'http://www.lancenet.com.br/gremio/', url: 'http://www.lancenet.com.br/rss/gremio/'},
37        {name: 'Globoesporte', website: 'http://globoesporte.globo.com/futebol/times/gremio/', url: 'http://globoesporte.globo.com/dynamo/semantica/editorias/plantao/futebol/times/gremio/feed.rss'},
38        {name: 'Canelada', website: 'http://canelada.com.br/category/gremio/', url: 'http://feeds.feedburner.com/CaneladaGremio'}
39      ]
40    },
41    
42    {
43    name: 'Flamengo',
44    website: 'http://www.flamengo.com.br',
45    twitter: 'cr_flamengo',
46    sources: [
47        {name: 'ESPN', website: 'http://www.espn.com.br/rss/flamengo', url: 'http://espn.estadao.com.br/rss/flamengo'},
48        {name: 'Gazeta Esportiva', website: 'http://www.gazetaesportiva.net/canal/20/flamengo/', url: 'http://www.gazetaesportiva.net/rss/20.xml'},
49        {name: 'Lancenet', website: 'http://www.lancenet.com.br/flamengo/', url: 'http://www.lancenet.com.br/rss/flamengo/'},
50        {name: 'Globoesporte', website: 'http://globoesporte.globo.com/futebol/times/flamengo/', url: 'http://globoesporte.globo.com/dynamo/semantica/editorias/plantao/futebol/times/flamengo/feed.rss'},
51        {name: 'Canelada', website: 'http://canelada.com.br/category/flamengo/', url: 'http://feeds.feedburner.com/CaneladaFlamengo'}
52      ]
53    },
54
55    {
56    name: 'Corinthians',
57    website: 'http://www.corinthians.com.br',
58    twitter: 'SiteCorinthians',
59    sources: [
60        {name: 'ESPN', website: 'http://www.espn.com.br/rss/corinthians', url: 'http://espn.estadao.com.br/rss/corinthians'},
61        {name: 'Gazeta Esportiva', website: 'http://www.gazetaesportiva.net/canal/19/corinthians/', url: 'http://www.gazetaesportiva.net/rss/19.xml'},
62        {name: 'Lancenet', website: 'http://www.lancenet.com.br/corinthians/', url: 'http://www.lancenet.com.br/rss/corinthians/'},
63        {name: 'Globoesporte', website: 'http://globoesporte.globo.com/futebol/times/corinthians/', url: 'http://globoesporte.globo.com/dynamo/semantica/editorias/plantao/futebol/times/corinthians/feed.rss'},
64        {name: 'Canelada', website: 'http://canelada.com.br/category/corinthians/', url: 'http://feeds.feedburner.com/CaneladaCorinthians'}
65      ]
66    }
67  ]
68
69
70  puts 'EMPTYING THE MONGODB DATABASE...'
71  Club.destroy_all
72  Source.destroy_all
73  Article.destroy_all
74
75
76  puts 'CREATING CLUBS:'
77  CLUBS.each do |club|
78    c = Club.where(name: club[:nome]).first
79    unless c
80      c = Club.create(name: club[:name], website: club[:website], twitter: club[:twitter])
81      puts "\t - Criando o clube '#{c.name}'"
82      club[:sources].each do |source|
83        c.sources << Source.create(source)
84      end
85    end
86  end
87
88  migrations.insert({file: __FILE__})
89  puts "\tDone!"
90end