-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (45 loc) · 2 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
55
56
57
58
59
60
61
62
from flask import Flask, render_template, request, send_file
from scrapper import stackoverflow_scrapper, wework_scrapper, remoteok_scrapper
from export import save_to_file
stack_db = {}
wework_db = {}
remoteok_db = {}
keyword_db = {}
app = Flask("Remote_Job_Scrapper")
@app.route("/")
def home():
return render_template("home.html")
@app.route("/result")
def result():
# stack_result=stack_result, total=len(stack_result)
search_input = request.args.get('search_input')
search_input = search_input.lower()
if search_input:
fromdb = keyword_db.get(search_input)
if fromdb:
stack_result = stack_db.get(search_input)
wework_result = wework_db.get(search_input)
remoteok_result = remoteok_db.get(search_input)
else:
stack_result = stackoverflow_scrapper(search_input)
stack_db[search_input] = stack_result
wework_result = wework_scrapper(search_input)
wework_db[search_input] = wework_result
remoteok_result = remoteok_scrapper(search_input)
remoteok_db[search_input] = remoteok_result
keyword_db[search_input] = "searched"
total = len(stack_result) + len(wework_result) + len(remoteok_result)
total = format(total, ",")
return render_template("result.html", search_input=search_input, stack_result=stack_result, wework_result=wework_result, remoteok_result=remoteok_result, total=total)
@app.route("/export")
def export():
search_input = request.args.get('search_input')
if keyword_db.get(search_input):
stack_result = stack_db.get(search_input)
wework_result = wework_db.get(search_input)
remoteok_result = remoteok_db.get(search_input)
save_to_file(stack_result, wework_result, remoteok_result)
else:
raise Exception
return send_file(filename_or_fp=f'Magic_Report.csv', mimetype='text/x-csv', attachment_filename=f'Magic_{search_input}_Report.csv', as_attachment=True)
app.run(host="192.168.0.4")