public
Description: A twitter <-> XMPP gateway with search and track and other good stuff.
Homepage: http://dustin.github.com/twitterspy/
Clone URL: git://github.com/dustin/twitterspy.git
Click here to lend your support to: twitterspy and make a donation at www.pledgie.com !
dustin (author)
Thu Oct 08 22:54:02 -0700 2009
commit  7ed2458368a8c12aa4c7f96aa501b0885eb9d1d9
tree    fe8be9b24bcc2aeebe2ca145b89b83bfada5bbd6
parent  fc78c312c1cb27e4a2f66a6f73a9013c0bd73f4a
twitterspy / twitterspy.tac
100644 87 lines (65 sloc) 2.561 kb
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
import sys
sys.path.insert(0, "lib/twitty-twister/twittytwister")
sys.path.insert(0, "lib/wokkel")
sys.path.insert(0, 'lib/twisted-longurl/lib')
sys.path.insert(0, "lib")
 
import ConfigParser
 
from twisted.application import service
from twisted.internet import task, reactor
from twisted.words.protocols.jabber import jid
from twisted.web import client
from wokkel.client import XMPPClient
from wokkel.generic import VersionHandler
from wokkel.keepalive import KeepAlive
from wokkel.disco import DiscoHandler
import twitter
 
from twitterspy import db
from twitterspy import cache
from twitterspy import config
from twitterspy import protocol
from twitterspy import xmpp_ping
from twitterspy import scheduling
from twitterspy import moodiness
from twitterspy import url_expansion
from twitterspy import adhoc_commands
 
# Set the user agent for twitter
twitter.Twitter.agent = "twitterspy"
 
client.HTTPClientFactory.noisy = False
 
application = service.Application("twitterspy")
 
def build_client(section):
    host = None
    try:
        host = config.CONF.get(section, 'host')
    except ConfigParser.NoSectionError:
        pass
 
    j = jid.internJID(config.CONF.get(section, 'jid'))
 
    xmppclient = XMPPClient(j, config.CONF.get(section, 'pass'), host)
 
    xmppclient.logTraffic = False
 
    # Stream handling protocols for twitterspy
    protocols = [protocol.TwitterspyPresenceProtocol,
                 protocol.TwitterspyMessageProtocol]
 
    for p in protocols:
        handler=p(j)
        handler.setHandlerParent(xmppclient)
 
    DiscoHandler().setHandlerParent(xmppclient)
    VersionHandler('twitterspy', config.VERSION).setHandlerParent(xmppclient)
    xmpp_ping.PingHandler().setHandlerParent(xmppclient)
    adhoc_commands.AdHocHandler().setHandlerParent(xmppclient)
    KeepAlive().setHandlerParent(xmppclient)
    xmppclient.setServiceParent(application)
 
    return xmppclient
 
 
cache.connect()
db.initialize()
 
build_client('xmpp')
try:
    build_client('xmpp_secondary')
except ConfigParser.NoSectionError:
    pass
 
task.LoopingCall(moodiness.moodiness).start(60, now=False)
task.LoopingCall(scheduling.resetRequests).start(scheduling.REQUEST_PERIOD,
                                                 now=False)
 
# If the expansion services are loaded, expansion will take effect
if (config.CONF.has_option('general', 'expand')
    and config.CONF.getboolean('general', 'expand')):
 
    # Load the url expansion services now, and refresh it every seven days.
    task.LoopingCall(url_expansion.expander.loadServices).start(86400 * 7)