This repository has been archived by the owner on Jan 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
simple-transcript.py
66 lines (48 loc) · 1.78 KB
/
simple-transcript.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
64
65
66
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import json
import datetime
def printTranscript(messages, outputFilename):
"""Prints a readable "transcript" from the given list of messages.
Assumes the input list is sorted."""
with open(outputFilename, 'wb') as outFile:
for message in messages:
name = message[u'name']
time = datetime.datetime.fromtimestamp(message[u'created_at']).strftime('%Y-%m-%d %H:%M')
# text is None for a photo message
if message[u'text'] is not None:
text = message[u'text']
else:
text = "(no text)"
if message[u'system'] is True:
system_padded = '(SYS) '
else:
system_padded = ''
if len(message[u'favorited_by']) is not 0:
favorites_padded = ' (' + str(len(message[u'favorited_by'])) + 'x <3)'
else:
favorites_padded = ''
if message[u'picture_url'] is not None:
pic = ' ; photo URL ' + message[u'picture_url']
else:
pic = ''
line = u'{0}{1}({2}){3}: {4}{5}\n'.format(
system_padded, name, time, favorites_padded, text, pic
)
outFile.write(line)
def main():
"""
Usage: simple-transcript.py transcript-filename.json output-filename.json
Assumes filename.json is a JSON GroupMe transcript in chronological order.
Times displayed in local timezone.
"""
if len(sys.argv) < 3:
print(main.__doc__)
sys.exit(1)
with open(sys.argv[1]) as transcriptFile:
transcript = json.load(transcriptFile)
printTranscript(transcript, sys.argv[2])
if __name__ == '__main__':
main()
sys.exit(0)