-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (40 loc) · 1009 Bytes
/
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
from flask import Flask, render_template, request, redirect, send_file
from scrapper import get_jobs
from exporter import save_to_file
app = Flask("SuperScrapper")
db = {} #fake DB
@app.route("/")
def home():
return render_template("potato.html")
@app.route("/report")
def report():
word = request.args.get('word')
if word:
word = word.lower()
existingJobs = db.get(word)
if existingJobs: #db에 이미 검색한 기록이 있다면
jobs = existingJobs
else:
jobs = get_jobs(word)
db[word] = jobs
else:
return redirect("/")
return render_template("report.html",
searchingBy = word,
resultsNumber = len(jobs),
jobs = jobs)
@app.route("/export")
def export():
try:
word = request.args.get('word')
if not word:
raise Exception()
word = word.lower()
jobs = db.get(word)
if not jobs:
raise Exception()
save_to_file(jobs)
return send_file("jobs.csv")
except:
return redirect("/")
app.run(host="0.0.0.0")