/
main_twitter.py
executable file
·32 lines (27 loc) · 1.09 KB
/
main_twitter.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
#!/usr/bin/env python3
import model, mturk, tweet_sender, time, os
from housepy import config, log, process, util
ts = tweet_sender.TweetSender()
process.secure_pid(os.path.abspath(os.path.join(os.path.dirname(__file__), "run")))
while True:
log.info("//////////")
clips = model.get_recent()
log.info("%s recent clips" % len(clips))
for clip in clips:
log.info("Checking %s %s %s" % (clip['t'], clip['hit_id'], util.datestring(clip['t'])))
struct = mturk.retrieve_result(clip['hit_id'])
if struct is None:
continue
model.mark_clip(clip['t'])
if 'nospeech' in struct and struct['nospeech'] == 'on':
log.info("--> no speech in clip")
continue
try:
for label in ('line_1', 'line_2', 'line_3'):
if label in struct and len(struct[label]):
message = '"%s"' % struct[label].strip('"')[:138]
ts.queue.put(message)
except Exception as e:
log.error(log.exc(e))
continue
time.sleep(30)