GeoRSS aggregator and Layar augmented reality server
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

feed.rb 1.8 KiB

il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. class Feed
  2. include MongoMapper::Document
  3. key :title, String, :default => "[New feed - hasn't been fetched yet]"
  4. key :feed_url, String # The URL of the RSS feed, not the website that owns it
  5. key :url, String # The URL of website. Called "link" in RSS 2.0
  6. key :description, String
  7. key :guid, String # Atom id or RSS guid
  8. key :generator, String
  9. key :last_fetched, Time, :default => nil
  10. timestamps!
  11. many :posts, :dependent => :destroy
  12. validates :title, :presence => true
  13. validates_format_of :feed_url, :with => URI::regexp(%w(http https)), :message => "must be a valid URL"
  14. after_create :get
  15. # Fetch and parse feed contents from web
  16. def self.get_all
  17. Feed.all.each { |f| f.get }
  18. end
  19. def get
  20. puts "Fetching feed: #{@url}"
  21. Feedzirra::Feed.add_common_feed_entry_element('georss:point', :as => :point)
  22. Feedzirra::Feed.add_common_feed_element('generator', :as => :generator)
  23. feed = Feedzirra::Feed.fetch_and_parse(@feed_url)
  24. self.set(
  25. :title => feed.title,
  26. :url => feed.url,
  27. :description => feed.description,
  28. :generator => feed.generator,
  29. :last_fetched => Time.now
  30. )
  31. feed.entries.each do |e|
  32. latlng = e.point.split(' ')
  33. attrs = {
  34. :title => e.title,
  35. :url => e.url,
  36. :author => e.author,
  37. :summary => e.summary,
  38. :content => e.content,
  39. :published => e.published,
  40. :guid => e.id,
  41. :loc => {
  42. :lng => latlng[1].to_f,
  43. :lat => latlng[0].to_f
  44. }
  45. }
  46. if Post.where(:url => e.url).size == 0
  47. self.posts << Post.create(attrs)
  48. else
  49. Post.set({:url => e.url}, attrs)
  50. end
  51. end
  52. end
  53. end