forked from opencog/ocpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocfeedbot
executable file
·61 lines (51 loc) · 1.41 KB
/
ocfeedbot
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
#!/usr/bin/python
#
# IRC b0t that keeps track of RSS feeds
#
# Licensed under the GNU General Public License v3
#
# Copyright (2009) by Akarsh Simha
import irclib
import feedparser
import os
import threading
import time
irc = irclib.IRC()
server = irc.server()
channels = [ "#opencog" ]
feeds = [ "http://wiki.opencog.org/wikihome/index.php?title=Special:RecentChanges&feed=atom",
"http://feeds.launchpad.net/opencog/revisions.atom",
"http://search.twitter.com/search.atom?q=%23opencog" ]
old_entries_file = os.environ.get("HOME") + "/.ocfeedbot.history"
server.connect( "irc.freenode.org", 6667, "ocfeedbot" )
msgqueue = []
def feed_refresh():
FILE = open( old_entries_file, "r" )
filetext = FILE.read()
FILE.close()
for feed in feeds:
NextFeed = False
d = feedparser.parse( feed )
for entry in d.entries:
id = entry.link.encode('utf-8')+entry.title.encode('utf-8')
if id in filetext:
NextFeed = True
else:
FILE = open( old_entries_file, "a" )
FILE.write( id + "\n" )
FILE.close()
msgqueue.append( entry.title.encode('utf-8') + " : " + entry.link.encode('utf-8') )
if NextFeed:
break;
t = threading.Timer( 900.0, feed_refresh )
t.start()
for channel in channels:
server.join( channel )
feed_refresh()
while 1:
while len(msgqueue) > 0:
msg = msgqueue.pop()
for channel in channels:
server.privmsg( channel, msg )
time.sleep(1)
irc.process_once()