flask-wallapop-watcher/app.py

40 lines
1.1 KiB
Python
Raw Normal View History

2017-08-06 00:38:21 +02:00
from flask import Flask, render_template, request
from forms import SearchForm
# Get data Wallapop
import json
from urllib3 import PoolManager
import urllib.parse
# Flask
2017-08-01 09:22:15 +02:00
app = Flask(__name__)
app.config['DEBUG'] = True
2017-08-06 00:38:21 +02:00
app.config['SECRET_KEY'] = 'mi secreto'
@app.route('/', methods=['GET', 'POST'])
def buscador():
form = SearchForm()
results = None
if form.validate_on_submit():
name = form.name.data
price_max = form.price_max.data or ''
# Search in Wallapop
http = PoolManager()
url_api = 'http://es.wallapop.com/rest/items?minPrice=&maxPrice={price_max}&dist=&order=creationDate-des&lat=41.398077&lng=2.170432&kws={kws}'.format(
kws=urllib.parse.quote(name, safe=''),
price_max=price_max
)
results = http.request('GET', url_api)
results = json.loads(
results.data.decode('utf-8')
)
results = results['items']
return render_template('items/buscador.html', form=form, results=results)
@app.route('/programadas')
def programadas():
return render_template('items/programadas.html')
2017-08-01 09:22:15 +02:00
if __name__ == '__main__':
app.run()