🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.python
Article #28665

Re: Unicode

#28665
From: Cezary Grądys
Date: Thu, 19 Dec 2019 12:16
79 lines
3177 bytes
W dniu 18.12.2019 o 11:07, damian@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
czarekgr@wa.onet.pl
Technical Details
Message-ID: <5dfb6a25$0$521$65785112@news.neostrada.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!news.samoylyk.net!weretis.net!feeder7.news.weretis.net!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
References: <5df7b2b9$0$503$65785112@news.neostrada.pl> <f2b06697-c712-4ebe-a2c4-a9b7bfab249e@googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!news.samoylyk.net!weretis.net!feeder7.news.weretis.net!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Subject: Re: Unicode
Newsgroups: pl.comp.lang.python
References: <5df7b2b9$0$503$65785112@news.neostrada.pl> <f2b06697-c712-4ebe-a2c4-a9b7bfab249e@googlegroups.com>
From: Cezary Grądys <czarekgr@wa.onet.pl>
Date: Thu, 19 Dec 2019 13:16:37 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2
MIME-Version: 1.0
In-Reply-To: <f2b06697-c712-4ebe-a2c4-a9b7bfab249e@googlegroups.com>
Lines: 79
Message-ID: <5dfb6a25$0$521$65785112@news.neostrada.pl>
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 88.156.142.171
X-Trace: 1576757797 unt-rea-b-01.news.neostrada.pl 521 88.156.142.171:57197
X-Complaints-To: abuse@news.neostrada.pl
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit