2024-08-21 04:39:30 +00:00
|
|
|
from fastapi import FastAPI
|
2024-08-22 04:08:39 +00:00
|
|
|
import urllib.parse
|
2024-08-19 14:13:16 +00:00
|
|
|
|
2024-08-21 06:24:31 +00:00
|
|
|
from config import __CONFIG__
|
2024-08-21 08:51:09 +00:00
|
|
|
import mysql_connector
|
2024-08-21 04:39:30 +00:00
|
|
|
from fastgpt_uploader import upload2fastgpt
|
|
|
|
from semanticscholar import search_paper
|
2024-08-22 17:15:51 +00:00
|
|
|
from rss import load_rss
|
2024-08-19 14:13:16 +00:00
|
|
|
|
2024-08-21 04:39:30 +00:00
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
def query(query:str):
|
|
|
|
res = []
|
2024-08-23 05:21:49 +00:00
|
|
|
try:
|
|
|
|
list = search_paper(query)
|
|
|
|
for i in list:
|
|
|
|
if mysql_connector.is_loaded(i['paperId']):
|
|
|
|
print(i['paperId'])
|
|
|
|
else:
|
|
|
|
print(i['citationStyles']['bibtex'])
|
|
|
|
res.append({
|
|
|
|
'id':i['paperId'],
|
|
|
|
'q':str(i['citationStyles']['bibtex']),
|
|
|
|
'a':str(i['abstract']),
|
|
|
|
'score':[]
|
|
|
|
})
|
|
|
|
print('New load: '+str(len(res))+'/'+str(len(list)))
|
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
2024-08-21 04:39:30 +00:00
|
|
|
return res
|
|
|
|
|
|
|
|
@app.get("/fastdoi")
|
|
|
|
async def get_reference(questions):
|
2024-08-21 10:16:00 +00:00
|
|
|
print('Search: '+questions)
|
2024-08-22 04:08:39 +00:00
|
|
|
res = query(urllib.parse.quote(questions))
|
|
|
|
if(upload2fastgpt(res)):
|
|
|
|
for i in res:
|
2024-08-21 08:51:09 +00:00
|
|
|
mysql_connector.new_load(i['id'])
|
2024-08-22 04:08:39 +00:00
|
|
|
return res
|
2024-08-21 04:39:30 +00:00
|
|
|
|
2024-08-22 17:15:51 +00:00
|
|
|
@app.get("/rss")
|
|
|
|
async def miniflux_rss():
|
2024-08-23 05:21:49 +00:00
|
|
|
return load_rss()
|
2024-08-22 17:15:51 +00:00
|
|
|
|
2024-08-21 04:39:30 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import uvicorn
|
2024-08-21 06:24:31 +00:00
|
|
|
uvicorn.run(app, host="127.0.0.1", port=8964)
|
2024-08-21 08:51:09 +00:00
|
|
|
mysql_connector.end_mysql()
|