Class: Artaius::Plugins::NewsFetcher
- Inherits:
-
Object
- Object
- Artaius::Plugins::NewsFetcher
- Includes:
- Cinch::Plugin
- Defined in:
- lib/artaius/plugins/news_fetcher.rb
Constant Summary collapse
- KAGDEV_RSS =
Internal: RSS address of KAG development blog.
'http://devlog.kag2d.com/rss'
- CHECK_TIME_LAPSE =
Internal: Time lapse between checking RSS feed for new posts.
1800
Instance Method Summary collapse
-
#latest_news(m) ⇒ Object
Internal: Send on the channel information about the latest post at KAG development blog and give a link to it.
-
#send_news ⇒ Object
Internal: Send latest news on channels.
Instance Method Details
#latest_news(m) ⇒ Object
Internal: Send on the channel information about the latest post at KAG development blog and give a link to it.
Returns nothing.
63 64 65 66 67 68 69 70 71 |
# File 'lib/artaius/plugins/news_fetcher.rb', line 63 def latest_news(m) news = News.order(:date).last = (news.) date = I18n.localize(news.date, :full) m.reply I18n.news_fetcher.latest_news(date, , news.title) m.reply I18n.news_fetcher.read_post(news.link) end |
#send_news ⇒ Object
Internal: Send latest news on channels.
Returns nothing.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/artaius/plugins/news_fetcher.rb', line 23 def send_news feed = RSS::Parser.parse open(KAGDEV_RSS).read last_post_title = feed.channel.item.title # Check, whether the latest title of the post at KAG development # blog is still the same, as it was, when the fetcher checked it last # time. return if unchanged?(last_post_title) item = feed.channel.item last_post_date = item.pubDate = item.dc_creator last_post_link = item.link News.create( :title => last_post_title, :date => last_post_date, :author => , :link => last_post_link ) = () short_link = open("http://clck.ru/--?url=#{last_post_link}").read Bot::CHANNELS.each do |chan| Channel(chan).send I18n.news_fetcher.news(, last_post_title, short_link) end rescue SocketError nil end |