-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss.py
105 lines (90 loc) · 3.65 KB
/
rss.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from irclib import SimpleIRCClient
import re
try:
import feedparser
except:
print 'Modulo FeedParser da import NON trovato'
class RssBot(SimpleIRCClient):
def __init__(self, channel, input, output):
SimpleIRCClient.__init__(self)
self.channel = channel
self.channels = {}
def on_welcome(self, c, e):
c.join(self.channel)
def on_privmsg(self, c, e):
self.do_command(e, e.arguments()[0])
messagepvt = e.arguments()[0]
print messagepvt
def on_kick(self, c, e):
print 'kicked from', e.target(), 'by', e.arguments()[1]
def getRssUrl(self, id='1', circuito='forumfree', query=''):
circuito = self.circuito
it = circuito == 'forumfree' and 'it' or 'net'
url = "http://"+circuito+"."+it+"/rss.php"
query_string = "?c=" + str(id) + query
complete_url = url + query_string
return complete_url
def getXmlTree(self, url, num = '1'):
tree = feedparser.parse(url)
return tree
def getValues(self, entries):
y = ['link', 'author', 'title', 'updated']
values = {}
for x in entries:
if x in y:
values[x] = self.transform(entries[x])
return values
def transform(self, text):
txt = text.replace('&', '&')
txt = re.sub("&l=(.*)&", '&', txt)
return txt
def run(self):
while True:
self.ircobj.process_once(0.2)
def on_invite(self, c, e):
channel = e.arguments()[0]
c.join(channel)
def on_namreply(self, c, e):
print e.target()
print e.arguments()
print e.source()
def on_pubmsg(self, c, e):
user = e.source().lower()
channel = e.target()
self.user = user
message = e.arguments()[0].lower()
if message == '%quit':
self.disconnect()
elif message[0:4] == '%rss':
if message[5:] == '':
print 'errore'
self.connection.privmsg(channel, 'Specificare dei parametri')
else:
args = message.split(' ')
cid = args[1]
circuito = args[2].lower()
# num = args[3]
print args
if cid == '':
self.connection.privmsg(channel, 'Specificare un ID')
elif circuito == '':
self.connection.privmsg(channel, 'Specificare il circuito(ff, fc, bf)')
else:
if circuito == 'ff' or circuito == 'forumfree':
self.circuito = 'forumfree'
elif circuito == 'fc' or circuito == 'forumcommunity':
self.circuito = 'forumcommunity'
elif circuito == 'bf' or circuito == 'blogfree':
self.circuito = 'blogfree'
else:
self.circuito = 'forumfree'
try:
url = self.getRssUrl(cid, circuito, '')
xml_tree = self.getXmlTree(url)
entries = xml_tree['entries'][1]
values = self.getValues(entries)
for x in values:
self.connection.privmsg(channel, x + ': ' + values[x])
pprint.pprint(values)
except:
self.connection.privmsg(channel, 'Errore, ID Forum/Blog non valido.')