45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
from fastapi import FastAPI
|
|
import urllib.parse
|
|
|
|
from config import __CONFIG__
|
|
import mysql_connector
|
|
from fastgpt_uploader import upload2fastgpt
|
|
from semanticscholar import search_paper
|
|
from rss import load_rss
|
|
|
|
app = FastAPI()
|
|
|
|
def query(query:str):
|
|
res = []
|
|
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)))
|
|
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():
|
|
load_rss()
|
|
|
|
if __name__ == '__main__':
|
|
import uvicorn
|
|
uvicorn.run(app, host="127.0.0.1", port=8964)
|
|
mysql_connector.end_mysql() |