arXiv-reader / app.py
broadfield's picture
Update app.py
76903ee verified
raw
history blame
1.51 kB
from flask import Flask, render_template, render_template_string, request
import requests
import xmltodict
import json
import random
app = Flask(__name__)
app.secret_key = "5rRRE6tk43D54e8e"
api="http://export.arxiv.org/api/query?search_query=SQ&start=0&max_results=MR"
style="""
.title_div{
font-size: x-large;
font-weight: 700;
margin-bottom: 10px;
}
.card_div{
background: #050523;
margin: 10px;
padding: 15px;
border-radius: 5px;
}
"""
@app.route("/", methods=['GET', 'POST'])
def home():
version = random.randint(1,11111111111111111111)
#def search(q,rn):
if request.method == 'POST':
# Create variables for easy access
q = request.form['query']
rn = request.form['count']
r=requests.get(s_url.replace("SQ",q).replace("MR",str(rn)))
cont=xmltodict.parse(r.content)['feed']['entry']
html=""
for i,c in enumerate(cont):
pdflink=c['id'].replace('/abs/','/pdf/')
html+=f"<div class='card_div' id='id{i}' onclick='fun_run()'>"
html+=f"<div class='titlebase'>{c['title']}</div>"
html+=f"<div>{c['summary']}</div>"
html+=f"<div><a href='{pdflink}' target='_blank'>{pdflink}</a></div>"
html+="</div>"
#return(json.dumps(cont,indent=4)),html
return render_template('index.html',version=version,html_out=html)
return render_template('index.html',version=version)
if __name__=="__main__":
app.run(host='0.0.0.0', port='8080')