From 9e9571a3c0605cb2c055c255c0bb23d5b46a77b3 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 5 Jul 2022 00:57:56 +0000 Subject: [PATCH] Write fixed stories to database --- apiserver/fix-stories.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/apiserver/fix-stories.py b/apiserver/fix-stories.py index cb01b13..7978556 100644 --- a/apiserver/fix-stories.py +++ b/apiserver/fix-stories.py @@ -1,7 +1,9 @@ -import logging -import database - import json +import logging + +import feed +import database +import search database.init() @@ -14,6 +16,7 @@ def fix_gzip_bug(story_list): sid = sid[0] story = database.get_story(sid) full_json = json.loads(story.full_json) + meta_json = json.loads(story.meta_json) text = full_json.get('text', '') count = text.count('�') @@ -21,6 +24,20 @@ def fix_gzip_bug(story_list): ratio = count / len(text) * 1000 print('Bad story:', sid, 'Num ?:', count, 'Ratio:', ratio) + if ratio < FIX_THRESHOLD: continue + + print('Attempting to fix...') + + valid = feed.update_story(meta_json, is_manual=True) + if valid: + database.put_story(meta_json) + search.put_story(meta_json) + print('Success') + else: + print('Story was not valid') + + time.sleep(3) + except KeyboardInterrupt: raise except BaseException as e: