-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweb.py
More file actions
50 lines (31 loc) · 1.02 KB
/
web.py
File metadata and controls
50 lines (31 loc) · 1.02 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
from flask import Flask, request, jsonify
import requests
from mongodb_persist import load_latest_jobs
app = Flask(__name__)
@app.route("/")
def index():
# find latest n (n=5) jobs
# find jobs in db and sort by created_at
# db.jobs.find().sort({created_at: -1}).limit(1)
limit = int(request.args.get("limit", 5))
job_docs = load_latest_jobs(limit)
return jsonify(job_docs)
@app.route("/search")
def search():
data = request.args
description = data.get("description", "")
location = data.get("location", "")
url = "https://jobs.github.com/positions.json?description={description}&location={location}".format(
description=description,
location=location
)
ext_resp = requests.get(url)
json_resp = ext_resp.json()
for job in json_resp:
job_id = job['id']
if job_id not in jobs_idx:
jobs_idx[job_id] = job
return jsonify(json_resp)
if __name__=="__main__":
port = 8000
app.run(port=port, debug=True)