Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. # example:
  2. # python hangout-filter.py Hangouts.json Ugw3axd-nDFKCvFsDi94AaABAQ | sort | tr '\n' ' ' > words.txt
  3.  
  4. # !/usr/bin/env python
  5.  
  6. import json
  7. import argparse
  8. import dateutil.parser
  9. import re
  10. import time
  11.  
  12. parser = argparse.ArgumentParser(
  13. description='Print conversations in readable format.')
  14. parser.add_argument('filename')
  15. parser.add_argument('conversation_id')
  16. args = parser.parse_args()
  17.  
  18. data = json.load(open(args.filename))
  19.  
  20. states = data['conversations']
  21. for state in states:
  22. conversation_state = state['conversation']
  23. if 'events' in state:
  24. conversations = state['events']
  25. for conversation in conversations:
  26. if 'chat_message' in conversation:
  27. message_content = conversation['chat_message']['message_content']
  28. if 'segment' in message_content:
  29. segment = message_content['segment']
  30. for line in segment:
  31. conversation_id = conversation['conversation_id']['id']
  32. if conversation_id == args.conversation_id:
  33. timestamp = time.localtime(int(conversation['timestamp']) / 1000000)
  34. user_id = conversation['sender_id']['gaia_id']
  35. try:
  36. uname = [p['fallback_name'] for p in conversation_state['conversation']['participant_data'] if p['id']['gaia_id'] == user_id][0]
  37. except:
  38. uname = user_id
  39. if 'text' in line:
  40. msg = line['text']
  41. elif 'type' in line and line['type'] == 'LINE_BREAK':
  42. msg = ''
  43. else:
  44. msg = line
  45. out = '{:<12}'.format(uname) + ' @ ' + time.asctime(timestamp) + ': ' + msg
  46. print(out.encode('ascii', 'ignore'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement