-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (40 loc) · 1.18 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from flask import Flask, render_template, request, redirect, send_file
from aladin import extract
from exporter import save_to_file
app = Flask("SuperScrapper")
db = {}
@app.route("/")
def home():
return render_template("index.html")
@app.route("/report")
def report():
word = request.args.get('word')
if word:
word = word.lower()
exisitingBooks = db.get(word)
if exisitingBooks:
books = exisitingBooks
else:
books = extract(word)
db[word] = books
else:
return redirect("/")
return render_template("report.html",
searchingBy=word,
resultsNumber=len(books),
books=books)
@app.route("/export")
def export():
try:
word = request.args.get('word')
if not word:
raise Exception()
word = word.lower()
books = db.get(word)
if not books:
raise Exception()
save_to_file(books)
return send_file("books.csv", mimetype="text/csv", attachment_filename='books.csv', as_attachment=True)
except:
return redirect("/")
app.run(host="127.0.0.1")