-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
76 lines (64 loc) · 1.98 KB
/
app.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from flask import Flask, request, jsonify
from flask_cors import CORS
from BazosScraper import BazosScraper
import asyncio
app = Flask(__name__)
CORS(app)
@app.route('/api/search', methods=['GET'])
def search():
search = request.args.get('search', '')
location = request.args.get('location')
distance = request.args.get('distance', '25')
min_price = request.args.get('min_price')
max_price = request.args.get('max_price')
order = request.args.get('order')
results_limit = request.args.get('results_limit')
if min_price:
min_price = int(min_price)
if max_price:
max_price = int(max_price)
if order:
order = int(order)
if results_limit:
results_limit = int(results_limit)
scraper = BazosScraper(
search=search,
location=location,
distance=distance,
min_price=min_price,
max_price=max_price,
order=order,
results_limit=results_limit
)
scraper.scrape()
return jsonify(scraper.listings.to_dict_list())
@app.route('/api/async_search', methods=['GET'])
async def async_search():
search = request.args.get('search', '')
location = request.args.get('location')
distance = request.args.get('distance', '25')
min_price = request.args.get('min_price')
max_price = request.args.get('max_price')
order = request.args.get('order')
results_limit = request.args.get('results_limit')
if min_price:
min_price = int(min_price)
if max_price:
max_price = int(max_price)
if order:
order = int(order)
if results_limit:
results_limit = int(results_limit)
scraper = BazosScraper(
search=search,
location=location,
distance=distance,
min_price=min_price,
max_price=max_price,
order=order,
results_limit=results_limit
)
await asyncio.to_thread(scraper.scrape)
return jsonify(scraper.listings.to_dict_list())
if __name__ == '__main__':
app.run()