Compare commits
No commits in common. "c4ffa25b336058eed6b4c8383f1af52f9725519e" and "a487c3163e126fe737ec57c8e73872741cbaf956" have entirely different histories.
c4ffa25b33
...
a487c3163e
@ -1 +0,0 @@
|
|||||||
{"bar": "foo", "foo": 3, "test": 4}
|
|
64
model.py
64
model.py
@ -1,64 +0,0 @@
|
|||||||
import random
|
|
||||||
import base64
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
|
|
||||||
class Model:
|
|
||||||
def __init__(self, filename = "model.json"):
|
|
||||||
self.filename = filename
|
|
||||||
self.sessions = None
|
|
||||||
if os.path.isfile(filename):
|
|
||||||
with open(filename) as f:
|
|
||||||
try:
|
|
||||||
self.sessions = json.load(f)
|
|
||||||
except:
|
|
||||||
self.sessions = {}
|
|
||||||
else:
|
|
||||||
self.sessions = {}
|
|
||||||
|
|
||||||
def handle_post(self, data):
|
|
||||||
pass
|
|
||||||
# handle post request data
|
|
||||||
|
|
||||||
def __enter__(self):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __exit__(self, exception_type, exception_value, traceback):
|
|
||||||
if not (exception_type or exception_value or traceback):
|
|
||||||
with open(self.filename, "w") as f:
|
|
||||||
json.dump(self.sessions, f)
|
|
||||||
if not os.path.isdir("backups"):
|
|
||||||
try:
|
|
||||||
os.mkdir("backups")
|
|
||||||
except FileExistsError:
|
|
||||||
print("backups is a file, no directory. Please delete yourself")
|
|
||||||
datestring = datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d-%H%M%S")
|
|
||||||
with open(f"backups/{datestring}_{self.filename}", "w") as f:
|
|
||||||
json.dump(self.sessions, f)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def create_session(self) -> str:
|
|
||||||
sessionname = base64.b32encode(bytearray(random.randint(0, 0xFF) for _ in range(10)))[:16].decode().lower()
|
|
||||||
self.sessions[sessionname] = {}
|
|
||||||
return sessionname
|
|
||||||
|
|
||||||
def subscribe(self, clientid, socket):
|
|
||||||
pass
|
|
||||||
# todo subscribe socket, match with id
|
|
||||||
|
|
||||||
|
|
||||||
def unsubscribe(self, socket):
|
|
||||||
pass
|
|
||||||
# remove socket from all clients
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
new session : ()
|
|
||||||
add player : uuid
|
|
||||||
"""
|
|
Loading…
Reference in New Issue
Block a user