Spaces:
Running
Running
Upload main.py
Browse files
main.py
CHANGED
@@ -3,18 +3,30 @@ import os, json, random
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
|
|
|
|
6 |
os.mkdir("./states")
|
7 |
|
8 |
@app.route("/")
|
9 |
def home():
|
10 |
return '''true'''
|
11 |
-
@app.route("
|
12 |
-
def get():
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
states = sorted(states, key=lambda x: os.path.getmtime(os.path.join("./states", x)), reverse=True)
|
15 |
states_parse = []
|
|
|
16 |
for s in states:
|
17 |
-
|
|
|
|
|
|
|
18 |
return json.dumps(states_parse)
|
19 |
@app.route("/states/<ide>/image.png")
|
20 |
def get_image(ide):
|
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
+
users = []
|
7 |
+
data = {}
|
8 |
os.mkdir("./states")
|
9 |
|
10 |
@app.route("/")
|
11 |
def home():
|
12 |
return '''true'''
|
13 |
+
@app.route("/<userid>/get_states")
|
14 |
+
def get(userid):
|
15 |
+
global users
|
16 |
+
global data
|
17 |
+
if not userid in users:
|
18 |
+
users.append(userid)
|
19 |
+
data[userid] = {}
|
20 |
+
data[userid]["views"] = []
|
21 |
+
states = os.listdir("./states")[-50:]
|
22 |
states = sorted(states, key=lambda x: os.path.getmtime(os.path.join("./states", x)), reverse=True)
|
23 |
states_parse = []
|
24 |
+
views = data[userid]["views"]
|
25 |
for s in states:
|
26 |
+
if s in views:
|
27 |
+
pass
|
28 |
+
else:
|
29 |
+
states_parse.append({"id":s, "text":open(f"./states/{s}/text", "r").read()})
|
30 |
return json.dumps(states_parse)
|
31 |
@app.route("/states/<ide>/image.png")
|
32 |
def get_image(ide):
|