From 4ccbbce2af2f45aff37cc6764bd414429eef3c6b Mon Sep 17 00:00:00 2001 From: a76yyyy Date: Sat, 3 Jun 2023 19:23:45 +0800 Subject: [PATCH] Reduce json dumps content size --- .github/src/extract_issue_body.py | 5 ++--- .github/workflows/update_content.yaml | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/src/extract_issue_body.py b/.github/src/extract_issue_body.py index 7591339..23be613 100644 --- a/.github/src/extract_issue_body.py +++ b/.github/src/extract_issue_body.py @@ -39,9 +39,8 @@ if len(issue_json) > 0 and 'name' in issue_json and 'author' in issue_json and ' if update and issue_json['filename'] != hfile['har'][issue_json['name']]['filename'] and os.path.exists(hfile['har'][issue_json['name']]['filename']): os.remove(hfile['har'][issue_json['name']]['filename']) - content_jsonstring = json.dumps(har_content, indent=4, ensure_ascii=False) with open(issue_json['filename'], 'w', encoding='utf8') as f: - f.write(content_jsonstring) + f.write(json.dumps(har_content, indent=4, ensure_ascii=False)) har = { 'name': issue_json['name'], @@ -50,7 +49,7 @@ if len(issue_json) > 0 and 'name' in issue_json and 'author' in issue_json and ' 'update': update, 'comments': issue_json.get('comments','').replace('\\r', '\r').replace('\\n', '\n').replace('\r','').replace('\n','
').strip(), 'filename': issue_json['filename'], - 'content': base64.b64encode(content_jsonstring.encode('utf8')).decode('utf8'), + 'content': base64.b64encode(json.dumps(har_content, ensure_ascii=False).encode('utf8')).decode('utf8'), 'date': hfile['har'][issue_json['name']]['date'] if update else time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), 'version': hfile['har'][issue_json['name']]['version'] if update else time.strftime('%Y%m%d', time.localtime()), 'commenturl': commenturl diff --git a/.github/workflows/update_content.yaml b/.github/workflows/update_content.yaml index d318f82..6e67428 100644 --- a/.github/workflows/update_content.yaml +++ b/.github/workflows/update_content.yaml @@ -2,7 +2,9 @@ name: Update Base64 Content on: workflow_dispatch: {} push: - paths: [tpls_history.json] + paths: + - tpls_history.json + - .github\workflows\update_content.yaml branches: - master - main @@ -32,7 +34,8 @@ jobs: for name, har in list(hfile['har'].items()): with open(har['filename'], 'rb') as f: har_content = f.read() - hfile['har'][name]['content'] = base64.b64encode(har_content).decode() + json_content = json.loads(har_content) + hfile['har'][name]['content'] = base64.b64encode(json.dumps(json_content, ensure_ascii=False).encode('utf8')).decode('utf8') json.dump(hfile, open('tpls_history.json', 'w', encoding='utf8'), indent=4, ensure_ascii=False) """ - name: Commit changes