-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarch
executable file
·39 lines (34 loc) · 1.17 KB
/
tarch
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
#!/usr/bin/python
import twitter_utils
import os
import sys
conf = twitter_utils.Conf(
os.path.join(os.path.dirname(sys.argv[0]), 'tarch.conf') )
(uid, last_sid, archpath_template, toffset,) = conf.read()
try:
stats = twitter_utils.get_statuses(uid)
except:
conf.increment_failure()
import sys
sys.exit(0)
def append_status_line(archpath_template, url, repurl, text, created_at):
import time
## GMT time str to GMT time struct
tcreated = time.strptime(created_at, '%a %b %d %H:%M:%S +0000 %Y')
## GMT time struct to local epoch to local time
tcreated = time.localtime(time.mktime(tcreated) + toffset * 60 * 60)
archpath = time.strftime(archpath_template, tcreated)
import codecs
output = codecs.getwriter('UTF-8')(open(archpath, 'a'))
output.write(u"%s\t%s\t%s\n" % (url, repurl, text,))
output.close()
for stat in stats:
sid = stat['id'] # Stat ID
if sid <= last_sid: # Skip stats already read
continue
(url, repurl, text,) = twitter_utils.format_fields(stat)
(text, dic,) = twitter_utils.expand_urls_in_text(text)
append_status_line(archpath_template,
url, repurl, text, stat['created_at'] )
last_sid = sid
conf.update_last_sid(last_sid)