From fcc11e8ce48860796acd6ac74ae9aabfa6484884 Mon Sep 17 00:00:00 2001 From: mxr612 Date: Fri, 23 Aug 2024 15:39:36 +0800 Subject: [PATCH] fix rss push bugs when < 100, improved code structure --- main.py | 34 ++++++++++++++++++++++++---------- rss.py | 24 +----------------------- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/main.py b/main.py index 3c57d17..a9473ea 100644 --- a/main.py +++ b/main.py @@ -5,11 +5,14 @@ from config import __CONFIG__ import mysql_connector from fastgpt_uploader import upload2fastgpt from semanticscholar import search_paper -from rss import load_rss +import rss app = FastAPI() -def query(query:str): +@app.get("/fastdoi") +async def get_reference(questions): + print('Search: '+questions) + questions = urllib.parse.quote(questions) res = [] try: list = search_paper(query) @@ -27,20 +30,31 @@ def query(query:str): print('New load: '+str(len(res))+'/'+str(len(list))) except Exception as e: print(str(e)) - return res - -@app.get("/fastdoi") -async def get_reference(questions): - print('Search: '+questions) - res = query(urllib.parse.quote(questions)) if(upload2fastgpt(res)): for i in res: mysql_connector.new_load(i['id']) return res @app.get("/rss") -async def miniflux_rss(): - return load_rss() +async def load_rss(): + count = 0 + loaded = [] + uploads = [] + for entry in rss.load_content(): + loaded.append(entry['id']) + uploads.append({ + 'q': entry['title'], + 'a': entry['content'] + }) + count += 1 + if len(loaded) >= 100 and upload2fastgpt(uploads): + rss.update(loaded) + loaded = [] + uploads = [] + if len(loaded) > 0 and upload2fastgpt(uploads): + rss.update(loaded) + print(f"Total entries loaded: {count}") + return f"Total entries loaded: {count}" if __name__ == '__main__': import uvicorn diff --git a/rss.py b/rss.py index fef228a..ae8fb5e 100644 --- a/rss.py +++ b/rss.py @@ -2,13 +2,10 @@ import miniflux import time from config import __CONFIG__ -from fastgpt_uploader import upload2fastgpt # Authentication using an API token client = miniflux.Client(__CONFIG__['miniflux_host'], api_key=__CONFIG__['miniflux_api']) -count = 0 - def load_content(): for i in range(1,10): try: @@ -26,26 +23,7 @@ def update(ids): client.update_entries(entry_ids=ids, status='read') return True except Exception as e: - print(f"Error uploading:{count} {e}") + print(f"Error updating: {e}") time.sleep(60) return False -def load_rss(): - count = 0 - loaded = [] - uploads = [] - for entry in load_content(): - loaded.append(entry['id']) - uploads.append({ - 'q': entry['title'], - 'a': entry['content'] - }) - count += 1 - if len(loaded) >= 100 and upload2fastgpt(uploads): - update(loaded) - loaded = [] - uploads = [] - if len(loaded) > 0: - update(loaded) - print(f"Total entries loaded: {count}") - return f"Total entries loaded: {count}"