This repository was archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweetorator.py
executable file
·63 lines (52 loc) · 1.68 KB
/
tweetorator.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
#!/usr/bin/env python
#coding: utf-8
import ConfigParser
import sys
import twitter
import logging
import tldb
import re
"""
THE NINJA IS STRONG WITH THIS ONE
TODO: FIX EVERYTHING
"""
__version__ = "0.1"
_api = None
initialized = False
def init():
global _api
cfg = ConfigParser.RawConfigParser()
cfg.read("tweetorator.cfg")
consumer_key = cfg.get("twitter", "consumer_key")
consumer_secret = cfg.get("twitter", "consumer_secret")
access_token_key = cfg.get("twitter", "access_token_key")
access_token_secret = cfg.get("twitter", "access_token_secret")
_api = twitter.Api(consumer_key = consumer_key,
consumer_secret = consumer_secret,
access_token_key = access_token_key,
access_token_secret = access_token_secret)
logging.debug("VerifyCredentials: %s" % _api.VerifyCredentials())
tldb.loadCfg('tldb.cfg')
def post_confession(text):
global _api
# Return if text only contains whitespace
if re.search(r'\S', text) is None:
logging.info("Confession only containing whitespace. Abort")
return
if not initialized:
init()
if len(text) > 140:
logging.info("Adding confession longer than 140")
try:
tldb.addConfession(text)
except:
logging.error("%s, 1, text was >>%s<<" % (sys.exc_info()[0], text))
pass
else:
logging.info("Adding confession shorter than 140")
try:
status = _api.PostUpdate(text)
tldb.addConfession(text, status.AsJsonString())
except:
logging.error("%s, 2, text was >>%s<<" % (sys.exc_info()[0], text))
pass