1
0

seeds.rb 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # This file should contain all the record creation needed to seed the database with its default values.
  2. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
  3. user = User.find_or_initialize_by_email("admin@example.com")
  4. user.username = "admin"
  5. user.password = "password"
  6. user.password_confirmation = "password"
  7. user.invitation_code = User::INVITATION_CODES.first
  8. user.admin = true
  9. user.save!
  10. unless user.agents.where(:name => "SF Weather Agent").exists?
  11. Agent.build_for_type("Agents::WeatherAgent", user,
  12. :name => "SF Weather Agent",
  13. :schedule => "10pm",
  14. :options => {:zipcode => "94103"}).save!
  15. end
  16. unless user.agents.where(:name => "XKCD Source").exists?
  17. Agent.build_for_type("Agents::WebsiteAgent", user,
  18. :name => "XKCD Source",
  19. :schedule => "every_1d",
  20. :type => "html",
  21. :options => {
  22. :url => "http://xkcd.com",
  23. :mode => :on_change,
  24. :expected_update_period_in_days => 5,
  25. :extract => {
  26. :url => {:css => "#comic img", :attr => "src"},
  27. :title => {:css => "#comic img", :attr => "title"}
  28. }
  29. }).save!
  30. end
  31. unless user.agents.where(:name => "iTunes Trailer Source").exists?
  32. Agent.build_for_type("Agents::WebsiteAgent", user, :name => "iTunes Trailer Source",
  33. :schedule => "every_1d",
  34. :options => {
  35. :url => "http://trailers.apple.com/trailers/home/rss/newtrailers.rss",
  36. :mode => :on_change,
  37. :type => "xml",
  38. :expected_update_period_in_days => 5,
  39. :extract => {
  40. :title => {:css => "item title", :text => true},
  41. :url => {:css => "item link", :text => true}
  42. }
  43. }).save!
  44. end
  45. unless user.agents.where(:name => "Rain Notifier").exists?
  46. Agent.build_for_type("Agents::TriggerAgent", user,
  47. :name => "Rain Notifier",
  48. :source_ids => user.agents.where(:name => "SF Weather Agent").pluck(:id),
  49. :options => {
  50. :expected_receive_period_in_days => "2",
  51. :rules => [{
  52. :type => "regex",
  53. :value => "rain|storm",
  54. :path => "conditions"
  55. }],
  56. :message => "Just so you know, it looks like '<conditions>' tomorrow in <zipcode>"
  57. }).save!
  58. end
  59. unless user.agents.where(:name => "Morning Digest").exists?
  60. Agent.build_for_type("Agents::DigestEmailAgent", user,
  61. :name => "Morning Digest",
  62. :schedule => "6am",
  63. :options => { :subject => "Your Morning Digest", :expected_receive_period_in_days => "30" },
  64. :source_ids => user.agents.where(:name => "Rain Notifier").pluck(:id)).save!
  65. end
  66. unless user.agents.where(:name => "Afternoon Digest").exists?
  67. Agent.build_for_type("Agents::DigestEmailAgent", user,
  68. :name => "Afternoon Digest",
  69. :schedule => "5pm",
  70. :options => { :subject => "Your Afternoon Digest", :expected_receive_period_in_days => "7" },
  71. :source_ids => user.agents.where(:name => ["iTunes Trailer Source", "XKCD Source"]).pluck(:id)).save!
  72. end