-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_json.py
More file actions
32 lines (29 loc) · 1012 Bytes
/
get_json.py
File metadata and controls
32 lines (29 loc) · 1012 Bytes
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
#!/usr/bin/env python
# -*- coding: utf8 -*-
import json, io
path = 'result.json'
opath = 'test.txt'
chatname = 'Dyvan Riders'
username = 'Mah Boi'
with io.open(opath, 'w', encoding='ISO-8859-1') as of:
with open(path, encoding='ISO-8859-1') as f:
data = json.load(f)
if data['chats']['list'][0]['name'] == chatname:
lst = data['chats']['list'][0]['messages']
for line in lst:
if 'from' in line:
if line['from'] == username:
if line['type'] == 'message':
if not isinstance(line['text'],(list,)):
msg = json.dumps(line['text'], ensure_ascii=True)
my_bytes = msg.encode()
asd = my_bytes.decode("unicode-escape").replace('"','') + '\n'
if asd != '\n':
of.write(asd)
else:
if len(line['text']) > 2:
msg = json.dumps(line['text'][2], ensure_ascii=True)
my_bytes = msg.encode()
asd = my_bytes.decode("unicode-escape").replace('"','') + '\n'
if asd != '\n':
of.write(asd)