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