-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·101 lines (70 loc) · 3.03 KB
/
app.py
File metadata and controls
executable file
·101 lines (70 loc) · 3.03 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import requests
import json
import os
import sys
from flask import Flask, render_template, request
app = Flask(__name__)
URL = "https://raw.githubusercontent.com/varora24/Find-My-Game/main/games.json"
@app.route('/', methods=['POST','GET'])
def index():
response = requests.get(URL)
data = response.json()
data = bubble_sort_func(data, 'Maxplayers')
if request.method == 'GET': # GET request is sent when html wants some information from the python script
return render_template('index.html', numgames = 0)
if request.method == 'POST': # POST request is sent when the html is sending sdata to the python code for processing
numplayers=request.form.get('numplayers')
genre = request.form.get('genre')
mode = request.form.get('mode')
dataout = findmatches(data, numplayers, genre, mode)
length = len(dataout)
return render_template("index.html", numgames = length, games = dataout,numelements = True)
def findmatches(data, numplayers, genre, mode):
dataout = []
genre = genre.strip()
mode = mode.strip()
if not numplayers:
numplayers = 1
if genre != "all":
if genre != "Cards" and genre != "Drawing":
genre = genre[1:-1]
numplayers = int(numplayers)
for game in data:
genrematch = False
modematch = False
if game["Maxplayers"] < numplayers and numplayers != 101:
break;
if game["Minplayers"] <= numplayers or numplayers == 101:
if genre != "all":
if game["Category"] == genre:
genrematch = True
else:
genrematch = True
if mode != "both":
if game["Format"] == mode or game["Format"] == "App/Website":
modematch = True
else:
modematch = True
if modematch == True and genrematch == True:
dataout.append(game)
return dataout
def check_valid(data):
defaults = {"Title": "No Name", "Minplayers": 1, "Maxplayers": 2, "Category": "Fun", "Description": "No Description", "Time": 30, "Price": 0, "Format": "Website", "URL": "No URL", "Picture": "https://i.ibb.co/SdxwqHd/Untitled-design-1-removebg-preview.png"}
for attribute in defaults:
if attribute not in data:
data[attribute] = defaults[attribute]
def bubble_sort_func(data, index):
length = len(data)
for i in range(length-1):
check_valid(data[i])
for j in range(0, length - i - 1):
if data[j][index] < data[j + 1][index]:
data[j], data[j + 1] = data[j + 1], data[j]
return data
@app.route('/ast', methods=['POST','GET'])
def ast():
print("Webpage change initiated")
if request.method == 'GET': # GET request is sent when html wants some information from the python script
return render_template('ast.html', showast = 0)
if request.method == 'POST':
return render_template('ast.html', showast = 1)