TechDev commited on
Commit
615c069
·
verified ·
1 Parent(s): 5f4045e

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -4
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("/get_states")
12
- def get():
13
- states = os.listdir("./states")
 
 
 
 
 
 
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
- states_parse.append({"id":s, "text":open(f"./states/{s}/text", "r").read()})
 
 
 
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):