-
Notifications
You must be signed in to change notification settings - Fork 2
/
gigfinder.py
executable file
·64 lines (44 loc) · 1.44 KB
/
gigfinder.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
from flask import Flask, render_template
import settings
from db import get_recent_gigs, search_for_gigs
from utils import jsonify_gigs
from celery import Celery
from craigslist.scraper import async_requests
from craigslist.craigslist_locations import locations
app = Flask(__name__)
app.config.from_object(settings)
def make_celery(app):
celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
return celery
celery = make_celery(app)
@celery.task(name="gigfinder.scrape")
def scrape(site):
async_requests(locations['US'], site=site)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/gigs/<provider>/')
@app.route('/gigs/')
def gigs(provider=None):
gigs = get_recent_gigs()
return jsonify_gigs(gigs)
@app.route('/search/<path:search_term>/')
def search(search_term):
gigs = search_for_gigs(search_term)
return jsonify_gigs(gigs)
@app.route('/update_craigslist/<site>/')
@app.route('/update_craigslist/')
def update_craigslist(site=None):
scrape.delay(site)
return "Craigslist update process run!"
if __name__ == "__main__":
port = 5555
app.run(port=port, debug=True)