Skip to content

Commit

Permalink
Parse timestamp_ms key in message
Browse files Browse the repository at this point in the history
  • Loading branch information
landalex committed Nov 3, 2019
1 parent fcb9c58 commit 80fb488
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions facebook-message-converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
tiebreaker_counter = 0
for message in data['messages']:
try:
message_datetime = datetime.fromtimestamp(int(message['timestamp']))
if 'timestamp_ms' in message:
message_timestamp = int(message['timestamp_ms']) / 1000
else:
message_timestamp = int(message['timestamp'])
message_datetime = datetime.fromtimestamp(message_timestamp)
if 'content' not in message:
# 'content' property contains the message text, other message types (stickers, media etc) use different
# properties which aren't handled here
Expand All @@ -46,7 +50,7 @@
time=message_datetime.strftime(TIME_FORMAT),
sender=sender.replace(' ', ''),
message=message_content.replace('\n', ' '))
heapq.heappush(heap, MessageTuple(timestamp=int(message['timestamp']), tiebreak_value=tiebreaker_counter,
heapq.heappush(heap, MessageTuple(timestamp=message_timestamp, tiebreak_value=tiebreaker_counter,
message=new_message))
tiebreaker_counter += 1
except KeyError as e:
Expand Down

0 comments on commit 80fb488

Please sign in to comment.