fastdoi/rss.py

52 lines
1.3 KiB
Python
Raw Normal View History

2024-08-22 17:15:51 +00:00
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:
tmp = client.get_entries(status=['unread'])['entries']
print(f"Downloaded {len(tmp)}")
return tmp
except Exception as e:
print(f"Error downloading: {e}")
time.sleep(10)
return None
def update(ids):
for i in range (1,10):
try:
client.update_entries(entry_ids=ids, status='read')
return True
except Exception as e:
print(f"Error uploading:{count} {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'],
'score':[]
})
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}")