-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoderator.py
executable file
·51 lines (39 loc) · 1.24 KB
/
moderator.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
#!/usr/bin/python
import tweepy
import string
import shelve
from oauthpost import getTweepyApi
from hashlib import sha1
post_account = "sydtraffic_cs"
moderator_account = "akent"
api = getTweepyApi(post_account)
history = shelve.open(".histfile-moderator")
def msg_hash(text):
return sha1(text).hexdigest()[:7]
def ask(text):
hash_str = msg_hash(text)
to_send = "%s %s" % (hash_str, text)[:140]
sent = api.send_direct_message(screen_name = moderator_account, text = to_send)
history[hash_str] = text
def take_action(action, text):
print "Got %s on text: %s" % (action, text)
def parse_response(text, user):
spl = text.split(" ", 2)
if (len(spl) < 2): return
hash = spl[0]
action = spl[1]
if history.has_key(hash) and user == moderator_account:
take_action(action, history[hash])
def check_for_responses():
for message in api.direct_messages(count=6):
parse_response(message.text, message.sender_screen_name)
def main():
#id = ask("So many parts of Anzac Pde under water #sydneytraffic")
#ask("@sydneytraffic pitterwater rd is the only road, what's why all the time congestion. www.onlineabc.com.au")
check_for_responses()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
quit()
history.close()