GeoRSS aggregator and Layar augmented reality server
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

feed.rb 2.1 KiB

12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. ensure_index :title
  12. many :posts, :dependent => :destroy
  13. validates :title, :presence => true
  14. validates_format_of :feed_url, :with => URI::regexp(%w(http https)), :message => "must be a valid URL"
  15. after_create :get
  16. # Fetch and parse feed contents from web
  17. def self.get_all
  18. Feed.all.each { |f| f.get }
  19. end
  20. def get
  21. puts "Fetching feed: #{@url}"
  22. Feedzirra::Feed.add_common_feed_entry_element('georss:point', :as => :point)
  23. Feedzirra::Feed.add_common_feed_entry_element('geo:lat', :as => :geo_lat)
  24. Feedzirra::Feed.add_common_feed_entry_element('geo:long', :as => :geo_long)
  25. Feedzirra::Feed.add_common_feed_element('generator', :as => :generator)
  26. feed = Feedzirra::Feed.fetch_and_parse(@feed_url)
  27. self.set(
  28. :title => feed.title,
  29. :url => feed.url,
  30. :description => feed.description,
  31. :generator => feed.generator,
  32. :last_fetched => Time.now
  33. )
  34. feed.entries.each do |e|
  35. if e.geo_lat && e.geo_long
  36. latlng = [e.geo_lat, e.geo_long]
  37. elsif e.point
  38. latlng = e.point.split(' ')
  39. else
  40. next
  41. end
  42. attrs = {
  43. :title => e.title,
  44. :url => e.url,
  45. :author => e.author,
  46. :summary => e.summary,
  47. :content => e.content,
  48. :published => e.published,
  49. :guid => e.id,
  50. :loc => {
  51. :lng => latlng[1].to_f,
  52. :lat => latlng[0].to_f
  53. }
  54. }
  55. if Post.where(:url => e.url).size == 0
  56. self.posts << Post.create(attrs)
  57. else
  58. Post.set({:url => e.url}, attrs)
  59. end
  60. end
  61. end
  62. end