Skip to content

Commit 7bb7ec3

Browse files
committed
DAY 13 OF 14 PYTHON CHALLENGE
1 parent 8f8e4e7 commit 7bb7ec3

File tree

1 file changed

+42
-52
lines changed

1 file changed

+42
-52
lines changed
Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from flask import Flask, render_template, request, redirect
2-
from scrapper import aggregate_subreddits, check_subreddit
3-
from remote import remote_jobs
4-
from sof import get_jobs
1+
from flask import Flask, render_template, request, redirect, send_file
2+
from scrapper import get_jobs, save
53

64
"""
75
These are the URLs that will give you remote jobs for the word 'python'
@@ -13,58 +11,50 @@
1311
Good luck!
1412
"""
1513

16-
remote = remote_jobs()
17-
sof = get_jobs()
14+
app = Flask("Remote Scrapper")
1815

19-
jobs = remote_jobs() + get_jobs()
16+
db = {}
2017

2118

22-
app = Flask("Remote World")
23-
24-
subreddits = [
25-
"javascript",
26-
"reactjs",
27-
"reactnative",
28-
"programming",
29-
"css",
30-
"golang",
31-
"flutter",
32-
"rust",
33-
"django"
34-
]
35-
3619
@app.route("/")
3720
def home():
38-
return render_template("home.html", subreddits=subreddits)
39-
40-
41-
@app.route("/read")
42-
def read():
43-
selected = []
44-
for subreddit in subreddits:
45-
if subreddit in request.args:
46-
selected.append(subreddit)
47-
posts = aggregate_subreddits(selected)
48-
posts.sort(key=lambda post: post['votes'], reverse=True)
49-
return render_template("read.html", selected=selected, posts=posts)
50-
51-
52-
@app.route("/add",methods=['POST'])
53-
def add():
54-
to_add = request.form.get('new-subreddit',None)
55-
if to_add:
56-
if "/" not in to_add:
57-
exists = check_subreddit(to_add)
58-
if exists:
59-
subreddits.append(to_add)
60-
return redirect("/")
61-
else:
62-
error = "That page does not exist."
21+
return render_template("index.html")
22+
23+
24+
@app.route("/search")
25+
def search():
26+
jobs = []
27+
term = request.args.get("term").lower()
28+
29+
if db.get(term):
30+
jobs.extend(db.get(term))
6331
else:
64-
error = "Write the name without /r/"
65-
else:
66-
error = "Write a text."
67-
return render_template("add-failed.html", error=error)
68-
32+
jobs.extend(get_jobs(term))
33+
34+
if len(jobs) == 0:
35+
return render_template("error.html", error_word=term, error_code=0)
36+
db[term] = jobs
37+
38+
quantities = len(jobs)
39+
keyword = term.capitalize()
40+
return render_template("result.html", jobs=jobs, quantities=quantities, keyword=keyword)
41+
42+
43+
@app.route("/download")
44+
def download():
45+
keyword = request.args.get("keyword")
46+
47+
if keyword is None:
48+
return render_template("error.html", error_word="", error_code=1)
49+
elif db.get(keyword.lower()) is None:
50+
return render_template("error.html", error_word="", error_code=1)
51+
52+
keyword = keyword.lower()
53+
lists = db.get(keyword)
54+
save(lists)
55+
56+
return send_file("jobs.csv", as_attachment=True, attachment_filename=f"{keyword}.csv")
57+
58+
6959

70-
app.run(host="0.0.0.0")
60+
app.run(host="0.0.0.0")

0 commit comments

Comments
 (0)