From 35a8d52fcabb9995460d4e7a96a14e8e2334d2d5 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 11 Oct 2022 13:03:53 +0800 Subject: [PATCH] feat: sort catalog --- catalog/sort.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 catalog/sort.py diff --git a/catalog/sort.py b/catalog/sort.py new file mode 100755 index 0000000..3e83873 --- /dev/null +++ b/catalog/sort.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import re +import json + +catalog = {} +for catalogPage in json.loads(open('raw.json').read()): + for pageInfo in catalogPage: + pageId = re.search(r'^/novel/57104/read_(\d+)\.html$', pageInfo['url'])[1] + catalog[pageInfo['name']] = pageId + +catalog = sorted(catalog.items(), key = lambda d: int(re.search(r'^第(\d+)章', d[0])[1])) +catalog = {x[0]: x[1] for x in catalog} + +print(json.dumps(catalog))