forked from odonnellryan/GigFinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gigfinder.py
executable file
·54 lines (40 loc) · 1.37 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
from flask import Flask, render_template
import settings
from db import get_recent_gigs, search_for_gigs, Gigs
from craigslist import craigslist_locations, scraper
from utils import jsonify_gigs
from celery import Celery
app = Flask(__name__)
app.config.from_object(settings)
def make_celery(flask_app):
celery = Celery(flask_app.import_name, broker=flask_app.config['CELERY_BROKER_URL'])
celery.conf.update(flask_app.config)
task_base = celery.Task
class ContextTask(task_base):
abstract = True
def __call__(self, *args, **kwargs):
with flask_app.app_context():
return task_base.__call__(self, *args, **kwargs)
celery.Task = ContextTask
return celery
c = make_celery(app)
@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):
scraper.async_requests(craigslist_locations.locations['US'], site=site)
return "Craigslist update process run!"
if __name__ == "__main__":
port = 5555
app.run(port=port, debug=True)