-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcars_app.py
53 lines (44 loc) · 1.82 KB
/
cars_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
from craigslist import *
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
from bokeh.embed import components
from io import BytesIO
from flask import Flask, render_template, request, redirect, send_file
app = Flask(__name__)
app.vars={}
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'GET':
return render_template('car_info.html')
else:
app.vars['make'] = request.form['Make']
app.vars['model'] = request.form['Model']
app.vars['year'] = request.form['Year']
app.vars['mileage'] = request.form['Mileage']
app.vars['status'] = request.form['Title Status']
app.vars['color'] = request.form['Color']
app.vars['type'] = request.form['Body Type']
return redirect('/result')
@app.route('/result', methods=['GET', 'POST'])
def result():
if request.method=='GET':
graph = draw_regional_fig_bokeh(app.vars['make'], app.vars['model'], app.vars['year'])
script, div = components(graph)
price, similar = predict(make=app.vars['make'], model=app.vars['model'],
year=app.vars['year'], mileage=app.vars['mileage'], title_status=app.vars['status'],
color=app.vars['color'], body_type=app.vars['type'])
price = '${}'.format(int(round(price)))
similar_html = ''
for car in similar:
desc = car[0]
link = car[1]
car_price = car[2]
similar_html += '<a href="https://boston.craigslist.org/{0}">{1}</a> ${2}<br>'.format(
link, desc, int(car_price))
return render_template('car_result.html', script=script, div=div, similar_html=similar_html, price=price)
else:
return redirect('/index')
if __name__ == "__main__":
port = int(os.environ.get("PORT", 33507))
app.run(port=port)