seeds.rb 4.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 => ENV['SEED_EMAIL'] || "admin@example.com")
  4. if user.persisted?
  5. puts "User with email '#{user.email}' already exists, not seeding."
  6. exit
  7. end
  8. user.username = ENV['SEED_USERNAME'] || "admin"
  9. user.password = ENV['SEED_PASSWORD'] || "password"
  10. user.password_confirmation = ENV['SEED_PASSWORD'] || "password"
  11. user.invitation_code = User::INVITATION_CODES.first
  12. user.admin = true
  13. user.save!
  14. puts
  15. puts
  16. unless user.agents.where(:name => "SF Weather Agent").exists?
  17. Agent.build_for_type("Agents::WeatherAgent", user,
  18. :name => "SF Weather Agent",
  19. :schedule => "10pm",
  20. :options => { 'location' => "94103", 'api_key' => "put-your-key-here" }).save!
  21. puts "NOTE: The example 'SF Weather Agent' will not work until you edit it and put in a free API key from http://www.wunderground.com/weather/api/"
  22. end
  23. unless user.agents.where(:name => "XKCD Source").exists?
  24. Agent.build_for_type("Agents::WebsiteAgent", user,
  25. :name => "XKCD Source",
  26. :schedule => "every_1d",
  27. :type => "html",
  28. :options => {
  29. 'url' => "http://xkcd.com",
  30. 'mode' => "on_change",
  31. 'expected_update_period_in_days' => 5,
  32. 'extract' => {
  33. 'url' => { 'css' => "#comic img", 'value' => "@src" },
  34. 'title' => { 'css' => "#comic img", 'value' => "@alt" },
  35. 'hovertext' => { 'css' => "#comic img", 'value' => "@title" }
  36. }
  37. }).save!
  38. end
  39. unless user.agents.where(:name => "iTunes Trailer Source").exists?
  40. Agent.build_for_type("Agents::WebsiteAgent", user, :name => "iTunes Trailer Source",
  41. :schedule => "every_1d",
  42. :options => {
  43. 'url' => "http://trailers.apple.com/trailers/home/rss/newtrailers.rss",
  44. 'mode' => "on_change",
  45. 'type' => "xml",
  46. 'expected_update_period_in_days' => 5,
  47. 'extract' => {
  48. 'title' => { 'css' => "item title", 'value' => ".//text()"},
  49. 'url' => { 'css' => "item link", 'value' => ".//text()"}
  50. }
  51. }).save!
  52. end
  53. unless user.agents.where(:name => "Rain Notifier").exists?
  54. Agent.build_for_type("Agents::TriggerAgent", user,
  55. :name => "Rain Notifier",
  56. :source_ids => user.agents.where(:name => "SF Weather Agent").pluck(:id),
  57. :options => {
  58. 'expected_receive_period_in_days' => "2",
  59. 'rules' => [{
  60. 'type' => "regex",
  61. 'value' => "rain|storm",
  62. 'path' => "conditions"
  63. }],
  64. 'message' => "Just so you know, it looks like '{{conditions}}' tomorrow in {{location}}"
  65. }).save!
  66. end
  67. unless user.agents.where(:name => "Morning Digest").exists?
  68. Agent.build_for_type("Agents::EmailDigestAgent", user,
  69. :name => "Morning Digest",
  70. :schedule => "6am",
  71. :options => { 'subject' => "Your Morning Digest", 'expected_receive_period_in_days' => "30" },
  72. :source_ids => user.agents.where(:name => "Rain Notifier").pluck(:id)).save!
  73. end
  74. unless user.agents.where(:name => "Afternoon Digest").exists?
  75. Agent.build_for_type("Agents::EmailDigestAgent", user,
  76. :name => "Afternoon Digest",
  77. :schedule => "5pm",
  78. :options => { 'subject' => "Your Afternoon Digest", 'expected_receive_period_in_days' => "7" },
  79. :source_ids => user.agents.where(:name => ["iTunes Trailer Source", "XKCD Source"]).pluck(:id)).save!
  80. end
  81. puts "See the Huginn Wiki for more Agent examples! https://github.com/cantino/huginn/wiki"