forked from cdzombak/groupme-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
simple-transcript.py
65 lines (45 loc) · 1.59 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
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import json
import datetime
def printTranscript(messages):
"""Prints a readable "transcript" from the given list of messages.
Assumes the input list is sorted."""
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 = ''
string = system_padded + name + ' (' + time + ')' + favorites_padded + ': ' + text + pic
print(string.encode(sys.stdout.encoding, errors='replace'))
def main():
"""Usage: simple-transcript.py filename.json
Assumes filename.json is a JSON GroupMe transcript in chronological order.
Times displayed in local timezone.
"""
if len(sys.argv) < 2:
print(main.__doc__)
sys.exit(1)
transcriptFile = open(sys.argv[1])
transcript = json.load(transcriptFile)
transcriptFile.close()
printTranscript(transcript)
if __name__ == '__main__':
main()
sys.exit(0)