From ccb09b52887dfc1d8931a1aae0450c8b4a281708 Mon Sep 17 00:00:00 2001 From: icoz Date: Tue, 27 Aug 2019 00:09:38 +0300 Subject: =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8F?= =?UTF-8?q?=20html=20=D1=81=20=D1=83=D1=87=D0=B5=D1=82=D0=BE=D0=BC=20?= =?UTF-8?q?=D1=81=D1=82=D0=B8=D0=BB=D0=B5=D0=B9=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B1=D0=B8=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=81=D0=B8=D0=B8=20=D1=81=D0=B0=D0=B9=D1=82=D0=B0?= =?UTF-8?q?.=20=D0=9A=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D1=8B=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B8=D0=B4=D1=83=D1=82=20?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=82=D0=BE=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- habraparse.py | 134 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 47 deletions(-) diff --git a/habraparse.py b/habraparse.py index 448bcd0..612c369 100755 --- a/habraparse.py +++ b/habraparse.py @@ -11,34 +11,63 @@ from habr.user import HabraUser, GeektimesUser __author__ = 'icoz' + def generate_comments(cmnts, id=0): - html_subcmnt = ''' - - ''' + # html_subcmnt = ''' + # + # ''' + # html_cmnt = ''' + #
  • + # + #
    + #
    + # + #
    + # {cmnt_text} + #
    + #
    + #
    + # ''' html_cmnt = ''' -
  • - -
    -
    - -
    - {cmnt_text} +
    +
    +
    + +
    -
    ''' - cmnts2 = tuple(filter(lambda x: x['p_id'] == id, cmnts)) - if len(cmnts2) == 0: return '' out = '' - for c in cmnts2: - out += html_cmnt.format(c_id=c['c_id'], p_id=id, user=c['author'], time=c['time'], cmnt_text=c['text']) - out += html_subcmnt.format(c_id = c['c_id'], list_cmnts=generate_comments(cmnts, c['c_id'])) + for c in filter(lambda x: x['p_id'] == id, cmnts): + # print(c) + padding = 20 if c['p_id'] == id else 0 + out += html_cmnt.format(c_id=c['c_id'], p_id=id, user=c['author'], time=c['time'], cmnt_text=c['text'], padding=padding) + # out += html_subcmnt.format(c_id = c['c_id'], list_cmnts=generate_comments(cmnts, c['c_id'])) return out + # html_HEAD_cmnt.format(len_cmnts=len(cmnts), list_cmnts=out) def prepare_html(topic, with_comments=False): t = topic @@ -56,6 +85,10 @@ def prepare_html(topic, with_comments=False): # 14.08.2018 # # https://dr.habracdn.net/habrcom/styles/1534243008/stylesheets.mobile.css + # 26/08/2019 + # https://m.habr.com/css/app.91a5df85.css + # https://dr.habracdn.net/habrcom/styles/1566568656/main.bundle.css + # html_head = ''' @@ -68,39 +101,46 @@ def prepare_html(topic, with_comments=False): - + -
    -
    -
    - -
    - -
    -

    {title}

    -
    - - {author} -
    - {text} -
    -
    +
    +
    +
    +
    +
    +
    +
    + ''' html_cmnts = ''' -
    -

    - Комментарии ({cmnts_count}) -

    -
      - {comments} -
    +
    +
    Комментарии {cmnts_count}
    +
    +
    + {comments} +
    +
    ''' html_foot = ''' +
    +
    +
    -
    -
    ''' @@ -182,7 +222,7 @@ def save_all_favs_for_user(username, out_dir, save_in_html=True, with_comments=F elif limit_cnt > 0: limit_cnt -= 1 topic_id = favs_id[topic_name] - print('Downloading "{}"...'.format(topic_name)) + print('Downloading "{}" ({})...'.format(topic_name, topic_id)) if save_by_name: t_name = topic_name.replace('/', '_').replace('\\', '_').replace('!', '.').replace(':', '.').replace(';', '.') -- cgit v1.2.3