-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsummarize.py
More file actions
27 lines (21 loc) · 805 Bytes
/
summarize.py
File metadata and controls
27 lines (21 loc) · 805 Bytes
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
#!/usr/bin/env python
from __future__ import print_function
import argparse
import json
def main(input, output):
lines = 0
with open(output, 'w', encoding='utf8') as fout:
for line in open(input):
rec = json.loads(line)
lng, lat = rec['coordinates']['coordinates']
txt = ' '.join(rec['text'].splitlines())
lines += 1
if lines % 10000 == 0:
print(lines, txt)
fout.write('%s,%s,%s,%s\n' % (rec['timestamp_ms'], lat, lng, txt))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--input', type=str, default='.twitter_cache')
parser.add_argument('--output', type=str, default='tweets.txt')
args = parser.parse_args()
main(args.input, args.output)