Aucune description http://j1x-huginn.herokuapp.com

seeds.rb 4.1KB

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("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. 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", 'attr' => "src" },
  30. 'title' => { 'css' => "#comic img", 'attr' => "title" }
  31. }
  32. }).save!
  33. end
  34. unless user.agents.where(:name => "iTunes Trailer Source").exists?
  35. Agent.build_for_type("Agents::WebsiteAgent", user, :name => "iTunes Trailer Source",
  36. :schedule => "every_1d",
  37. :options => {
  38. 'url' => "http://trailers.apple.com/trailers/home/rss/newtrailers.rss",
  39. 'mode' => "on_change",
  40. 'type' => "xml",
  41. 'expected_update_period_in_days' => 5,
  42. 'extract' => {
  43. 'title' => { 'css' => "item title", 'text' => true},
  44. 'url' => { 'css' => "item link", 'text' => true}
  45. }
  46. }).save!
  47. end
  48. unless user.agents.where(:name => "Rain Notifier").exists?
  49. Agent.build_for_type("Agents::TriggerAgent", user,
  50. :name => "Rain Notifier",
  51. :source_ids => user.agents.where(:name => "SF Weather Agent").pluck(:id),
  52. :options => {
  53. 'expected_receive_period_in_days' => "2",
  54. 'rules' => [{
  55. 'type' => "regex",
  56. 'value' => "rain|storm",
  57. 'path' => "conditions"
  58. }],
  59. 'message' => "Just so you know, it looks like '<conditions>' tomorrow in <location>"
  60. }).save!
  61. end
  62. unless user.agents.where(:name => "Morning Digest").exists?
  63. Agent.build_for_type("Agents::DigestEmailAgent", user,
  64. :name => "Morning Digest",
  65. :schedule => "6am",
  66. :options => { 'subject' => "Your Morning Digest", 'expected_receive_period_in_days' => "30" },
  67. :source_ids => user.agents.where(:name => "Rain Notifier").pluck(:id)).save!
  68. end
  69. unless user.agents.where(:name => "Afternoon Digest").exists?
  70. Agent.build_for_type("Agents::DigestEmailAgent", user,
  71. :name => "Afternoon Digest",
  72. :schedule => "5pm",
  73. :options => { 'subject' => "Your Afternoon Digest", 'expected_receive_period_in_days' => "7" },
  74. :source_ids => user.agents.where(:name => ["iTunes Trailer Source", "XKCD Source"]).pluck(:id)).save!
  75. end
  76. puts "See the Huginn Wiki for more Agent examples! https://github.com/cantino/huginn/wiki"