W dniu 18.12.2019 o 11:07,
dam...@swistowski.org pisze:
> - print(p['content']) # w tej linii błąd, chociaż kilka wypisuje.
> + print(p.get('content', '')) # w tej linii błąd, chociaż kilka wypisuje.
>
Ostatecznie zrobiłem w taki sposób, można ulepszyć, ale juz jest
czytelnie:
#!/usr/bin/python3.7
import json
import datetime
def marginesy(l, margines):
k = "\n" + margines
l = k.join(l.split("\n"))
return (l)
for i in range(29, 0, -1):
file = 'message_' + str(i) + '.json'
with open(file) as json_file:
data = json.load(json_file)
sender_time_old = 'dupa'
for p in reversed(data['messages']):
sender_name = p["sender_name"].encode("latin").decode("utf")
if sender_name == 'Cezary Grądys':
margines = ''
else:
margines = '\t'
time = datetime.datetime.fromtimestamp(p["timestamp_ms"] /
1000.0).strftime("%Y-%m-%d %H:%m")
sender_time = sender_name + ' ' + time
if sender_time_old != sender_time:
print("\n" + margines + sender_time)
sender_time_old = sender_time
if 'content' in p:
print(margines +
marginesy(p['content'].encode("latin").decode("utf"), margines))
if 'gifs' in p:
print(margines, end='')
print(p['gifs'])
if 'photos' in p:
print(margines, end='')
print(p['photos'])
if 'sticker' in p:
print(margines, end='')
print(p['sticker'])
if 'videos' in p:
print(margines, end='')
print(p['videos'])
if 'share' in p:
print(margines, end='')
print(p['share'])
if 'reactions' in p:
print(margines, end='')
print(p['reactions'])
--
Cezary Grądys
czar...@wa.onet.pl