-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunBot.py
69 lines (53 loc) · 1.78 KB
/
RunBot.py
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
60
61
62
63
64
65
66
67
68
69
#based on code from Meenakshi Agarwal - https://www.techbeamers.com/create-python-irc-bot/
#shortlink: https://archive.st/ef60
from time import sleep
import feedparser
from irc_class import *
import os
import random
from datetime import datetime
from datetime import timedelta
from time import mktime
## IRC Config
server = "" # Provide a valid server IP/Hostname
port = 6697
channel = "#test"
botnick = "testbot"
botnickpass = "guido"
botpass = "<%= @guido_password %>"
irc = IRC()
irc.connect(server, port, channel, botnick, botpass, botnickpass)
startdate = None
pollinterval = 5
currenttime = datetime.now()
nextpoll = datetime.now()+ timedelta(seconds=20)
hoursback = pollinterval
while True:
currenttime = datetime.now()
if currenttime > nextpoll:
nextpoll = currenttime + timedelta(hours=pollinterval)
print("whee")
urls = ['https://example.com/feed',
]
feeddata = {}
for url in urls:
feeddata[url] = feedparser.parse(url)
feeds = {}
for feed in feeddata:
for post in feeddata[feed]['entries']:
print(feeddata[feed]['feed']["title"])
print(post["title"])
print(post["published"])
print(post["link"])
posttime = datetime.fromtimestamp(mktime(post["published_parsed"]))
if posttime > currenttime - timedelta(hours=pollinterval):
irc.send(channel, post["title"] + " - " + post["link"])
try:
text = irc.get_response()
print(text)
sleep(2)
except KeyboardInterrupt:
print("Ok ok, quitting")
sys.exit(1)
except:
print("Something else went wrong")