/
ravensBot.rb
59 lines (51 loc) · 2.39 KB
/
ravensBot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
54
55
56
57
58
59
require 'redditkit'
require 'rss'
require 'date'
require 'net/http'
require 'json'
userPassFile = File.read('./redditBots/ravensBot.json')
userPassHash = JSON.parse(userPassFile)
client = RedditKit::Client.new userPassHash['username'], userPassHash['password']
videoFeedUrl = "http://www.baltimoreravens.com/cda-web/rss-module.htm?tagName=Videos"
newsFeedUrl = "http://www.baltimoreravens.com/cda-web/rss-module.htm?tagName=News"
photosFeedUrl = "http://www.baltimoreravens.com/cda-web/feeds/photo"
time = Date.today-1
title = "BaltimoreRavens.com Content from #{time.strftime("%Y-%m-%d")}"
output = "####{title}###\n\n"
videoRss = RSS::Parser.parse(videoFeedUrl, false)
output << "##Videos##\n\n"
videoRss.items.each do |item|
if item.pubDate.to_date > time-1
begin
videoPageUrl = /<li class="download-audio "><a href="(.+)">/.match(Net::HTTP.get(URI(item.link)))[1]
videoUrl = "#{/(.+)32k.mp3/.match(videoPageUrl)[1]}5000k.mp4"
output << "[**#{item.title}**](#{videoUrl}) - #{item.description}\n\n"
rescue
end
end
end
newsRss = RSS::Parser.parse(newsFeedUrl, false)
output << "##News##\n\n"
newsRss.items.each do |item|
if item.pubDate.to_date > time-1
output << "[**#{item.title}**](#{item.link}) - #{item.description}\n\n"
end
end
photosRss = RSS::Parser.parse(photosFeedUrl, false)
output << "##Photos##\n\n"
photosRss.items.each do |item|
if item.pubDate.to_date > time-1
output << "[**#{item.title}**](#{item.link}) - #{item.description}\n\n"
end
end
output << "-----------------------------------------\n\n"
output << "Hi, I am a reddit bot created by /u/_j_. Please send any comments, feedback, or requests as a pm to him."
puts output
puts "\n\n\n"
puts "-------------------------------------------\nSubmitting to log subreddit\n-----------------------------------------------------------"
puts client.submit("[RavensBot] #{title}", "ravensbot", options={:text => output})
puts "--------------------------------------------------\nSleeping for 15 minutes so we don't time out\n--------------------------------------------------------"
sleep(900)
puts "--------------------------------------------------\nSubmitting to Ravens subreddit\n-------------------------------------------------------"
puts client.submit("[RavensBot] #{title}", "ravens", options={:text => output})
puts "--------------------------------------------------\nDone!\n-------------------------------------------"