GeoRSS aggregator and Layar augmented reality server
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

69 líneas
1.8 KiB

  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