-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
53 lines (40 loc) · 1.2 KB
/
Copy pathapp.py
File metadata and controls
53 lines (40 loc) · 1.2 KB
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
from flask import Flask, render_template, request, redirect, send_file
from utils.cache import TTLCache
from services.job_search import JobSearchService
from services.job_export import export_jobs_csv
app = Flask("JobScrapper")
cache = TTLCache()
service = JobSearchService()
@app.route("/")
def home():
return render_template("home.html")
@app.route("/search")
def search():
keyword = request.args.get("keyword")
if keyword == None:
return redirect("/")
cached = cache.get(keyword)
if cached:
jobs = cached
else:
jobs = service.search(keyword)
cache.set(keyword, jobs)
return render_template("search.html", jobs = jobs, keyword = keyword)
@app.route("/export")
def export():
keyword = request.args.get("keyword")
if not keyword:
return redirect("/")
jobs = _get_jobs(keyword)
file_path = export_jobs_csv(jobs, keyword)
return send_file(file_path, as_attachment=True)
def _get_jobs(keyword: str):
cached = cache.get(keyword)
if cached:
return cached
jobs = service.search(keyword)
cache.set(keyword, jobs)
return jobs
if __name__ == "__main__":
# app.run("0.0.0.0")
app.run(port = 5001)