Add upload and download to python server

This commit is contained in:
Michael Mikovsky
2025-05-25 13:38:50 -06:00
parent ae147771cb
commit 5d727cf359
3 changed files with 111 additions and 15 deletions
+15 -5
View File
@@ -1,9 +1,14 @@
import os
ROOT = os.path.dirname(__file__)
METADATA_FILE = os.path.join(ROOT, 'metadata.json')
DATA_ROOT = os.path.join(os.path.dirname(__file__), 'data')
METADATA_PATH4 = os.path.join(ROOT, 'metadata.json')
API_KEY_PATH = os.path.join(ROOT, 'api_key.txt')
MODIFIED_HEADER = 'modified'
API_KEY_HEADER = 'api_key'
def mkdir(path):
if not os.path.exists(path):
os.makedirs(path)
@@ -18,13 +23,18 @@ def read(path):
if not os.path.exists(path):
return None
try:
with open(path) as f:
with open(path, 'rb') as f:
return f.read()
except:
except Exception as e:
print(f"Error reading file {path}: {e}")
return None
def write(path, data):
if not os.path.exists(path):
with open(path, mode='a'): pass
with open(path, 'w') as f:
with open(path, mode='ab'): pass
if isinstance(data, str):
data = str.encode(data)
with open(path, 'wb') as f:
f.write(data)