TechDev commited on
Commit
9d246a0
·
verified ·
1 Parent(s): 579c41f

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -1
main.py CHANGED
@@ -3,16 +3,27 @@ import os, json
3
 
4
  app = Flask(__name__)
5
 
 
 
6
  @app.route("/")
7
  def home():
8
  return '''true'''
9
  @app.route("/get_states")
10
  def get():
11
  states = os.listdir("./states")
 
12
  states_parse = []
13
  for s in states:
14
  states_parse.append({"id":s, "text":open(f"./states/{s}/text", "r").read()})
15
  return json.dumps(states_parse)
16
  @app.route("/states/<ide>/image.png")
17
  def get_image(ide):
18
- return send_file(f"./states/{ide}/image.png")
 
 
 
 
 
 
 
 
 
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(directorio, 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):
21
+ return send_file(f"./states/{ide}/image.png")
22
+ @app.route("/add_state", methods=["POST"])
23
+ def add_state():
24
+ text = request.form["text"]
25
+ file = request.form["file"]
26
+ ide = random.randint(100000,999999)
27
+ os.mkdir(f"./states/{ide}")
28
+ open(f"./states/{ide}/text", "w").write(text)
29
+ file.save(f"./states/{ide}/image.png")