|
import uuid |
|
import os |
|
import json |
|
|
|
|
|
def store_user_data(user_id, storage_type, storage_data): |
|
|
|
base_dir = "./user_data/" |
|
user_dir = base_dir + str(user_id) |
|
os.makedirs(user_dir, exist_ok=True) |
|
|
|
file_path = os.path.join(user_dir, f"{storage_type}_{user_id}.json") |
|
|
|
|
|
if os.path.exists(file_path): |
|
try: |
|
with open(file_path, 'r') as file: |
|
existing_data = json.load(file) |
|
|
|
existing_data.update(storage_data) |
|
data = existing_data |
|
except json.JSONDecodeError: |
|
|
|
pass |
|
|
|
|
|
with open(file_path, 'w') as file: |
|
json.dump(storage_data, file, indent=4) |
|
|
|
def store_user_questionnaire(user_id, storage_data): |
|
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.exists(file_path): |
|
try: |
|
with open(file_path, 'r') as file: |
|
existing_data = json.load(file) |
|
|
|
existing_data.update(storage_data) |
|
data = existing_data |
|
except json.JSONDecodeError: |
|
|
|
pass |
|
|
|
|
|
with open(file_path, 'w') as file: |
|
json.dump(storage_data, file, indent=4) |
|
|