-
Notifications
You must be signed in to change notification settings - Fork 3
/
HangoutsParser.py
32 lines (25 loc) · 1.36 KB
/
HangoutsParser.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
import time
import json
def parseHangouts(locationName, beginTimeFrame = 0, endTimeFrame = int(time.time())):
data = json.load(open(locationName,'r'))
conversations = []
for conversation in data['conversation_state']:
participantsarray = []
participantsdict={}
#participants
for participants in conversation['conversation_state']['conversation']['participant_data']:
participantsdict[participants['id']['gaia_id']] = participants['fallback_name']
participantsarray.append(participants['fallback_name'])
for message in conversation['conversation_state']['event']:
try:
#original timestap is in microseconds that is why we need to devide the value by 1000000
timestamp = int(message['timestamp'])//1000000
if int(timestamp) < endTimeFrame and int(timestamp) > beginTimeFrame:
hangoutsInfo = timestamp, 'Hangouts', \
"From: " + str(participantsdict[message['sender_id']['gaia_id']]) + ", " \
"Message: " + str(message['chat_message']['message_content']['segment'][0]['text']) + ", " \
"Participants: " + str(participantsarray)
conversations.append(hangoutsInfo)
except KeyError:
pass
return conversations