repl.it
@RohilPatel/

FairPrices

Python

for The hackathon 2019

fork
loading
Files
  • main.py
  • backend
  • planning
  • static
  • templates
  • useless
  • Database
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.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
#THIS IS THE FINAL VERSION OF THE HACKATHON CONTEST!

from flask import Flask, request, render_template, abort #, jinja
from backend.models import products 
import backend.write
# app = Flask(__name__, static_folder='.', root_path='/home/runner')

app = Flask(__name__, static_folder='./static', template_folder='./templates')
app.config.update(TEMPLATES_AUTO_RELOAD=True)

print('start')
@app.route('/')
def root():
    print("root")
    return render_template('./index.html')# main page

def product_index():
    products.products_info()

## post new products to track
@app.route('/products', methods= ['POST'])
def post_product():
    upc = request.args.get('upc')
    name = request.args.get('name')
    price = request.args.get('price')
    product = products.add_product(upc, name)
    product.add_price("userid", price)


# params for post: price
@app.route('/products/<UPC>', methods= ['GET', 'POST'])
def show_product(upc): #, methods=['GET', 'POST'] 

  product = products.get_product(upc)
  # if product == None:
    #-----> send seach webpage
  if product is None: 
    abort(404, description="Product not found!")

  print(f"product: {product}")
  if request.method == 'POST':
    submitted_price = request.args.get('price')
    location = request.args.get('location') #do geolocation in HTML and pass values in the request  // need JS in front end
    try: 
      tesst = submitted_price + 1 #testing if its a number
    except TypeError:
      return render_template('./products.html', product=product.as_dict(), average_price=product.get_average_price()) #product search

    if submitted_price != None and submitted_price > 0:
        product.submit_price("user_id", submitted_price)

  return render_template('./products.html', product=product.as_dict(), average_price=product.get_average_price()) #product search

if __name__ == '__main__':
    app.run(host='0.0.0.0', port='3000')



# price calculation moved to priceCalculation.py
#ok
?