seeds.rb 4.3 KB

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