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.4 KiB

il y a 12 ans
il y a 12 ans
il y a 12 ans
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 :last_fetched, Time, :default => nil
  8. timestamps!
  9. many :posts, :dependent => :destroy
  10. validates :title, :presence => true
  11. validates_format_of :feed_url, :with => URI::regexp(%w(http https)), :message => "must be a valid URL"
  12. after_create :get
  13. # Fetch and parse feed contents from web
  14. def get
  15. Feedzirra::Feed.add_common_feed_entry_element('georss:point', :as => :point)
  16. feed = Feedzirra::Feed.fetch_and_parse(@feed_url)
  17. self.set(
  18. :title => feed.title,
  19. :url => feed.url,
  20. :description => feed.description,
  21. :last_fetched => Time.now
  22. )
  23. feed.entries.each do |e|
  24. # puts "#{e.title} point: #{e.point}"
  25. latlng = e.point.split(' ')
  26. self.posts << Post.create(
  27. :title => e.title,
  28. :url => e.url,
  29. :author => e.author,
  30. :summary => e.summary,
  31. :content => e.content,
  32. :published => e.published,
  33. :loc => {
  34. :lng => latlng[1].to_f,
  35. :lat => latlng[0].to_f
  36. }
  37. )
  38. end
  39. end
  40. end