Frontend weiterarbeit, Client Server datenaustausch und sync, fertiggestellt.
This commit is contained in:
@@ -15,6 +15,7 @@ def get_config():
|
||||
return jsonify({'error': 'Token ID is missing'}), 400
|
||||
|
||||
config_file = os.path.join('config', f'{token_id}.json')
|
||||
data_file = os.path.join('data', f'{token_id}.json') # angenommen, die Daten befinden sich im Ordner 'data'
|
||||
|
||||
if not os.path.exists(config_file):
|
||||
return jsonify({'error': 'Config not found for the specified token'}), 404
|
||||
@@ -22,21 +23,23 @@ def get_config():
|
||||
with open(config_file, 'r') as file:
|
||||
config = json.load(file)
|
||||
|
||||
|
||||
data_file = os.path.join('config', f'{token_id}.json')
|
||||
|
||||
with open(data_file, 'r') as file:
|
||||
data = json.load(file)
|
||||
# Extract and include last timestamp in the response
|
||||
try:
|
||||
config['last_timestamp'] = data['timestamps'][len(data['timestamps'])-1]
|
||||
except:
|
||||
config['last_timestamp']=0
|
||||
if os.path.exists(data_file):
|
||||
with open(data_file, 'r') as file:
|
||||
data = json.load(file)
|
||||
try:
|
||||
last_timestamp = max(data.keys()) # Den neuesten Zeitstempel aus den Schlüsseln der Daten extrahieren
|
||||
print(last_timestamp)
|
||||
config['last_timestamp'] = last_timestamp
|
||||
except ValueError:
|
||||
config['last_timestamp'] = 0
|
||||
else:
|
||||
config['last_timestamp'] = 0
|
||||
|
||||
return jsonify(config), 200
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
# Route to set new data
|
||||
|
||||
|
||||
@@ -91,28 +94,23 @@ def write_json_file(token_id, new_data):
|
||||
with open(file_path, 'w') as file:
|
||||
json.dump(new_data, file)
|
||||
|
||||
def merge_json(old_json, new_json):
|
||||
if not isinstance(old_json, dict) or not isinstance(new_json, dict):
|
||||
return old_json
|
||||
def merge_json(json1, json2):
|
||||
# Wenn ein JSON leer ist, gib einfach das andere zurück
|
||||
if not json1:
|
||||
return json2
|
||||
if not json2:
|
||||
return json1
|
||||
|
||||
for key, value in new_json.items():
|
||||
if key not in old_json:
|
||||
old_json[key] = value
|
||||
elif isinstance(value, list):
|
||||
if key not in old_json:
|
||||
old_json[key] = []
|
||||
if key == "timestamps":
|
||||
for item in value:
|
||||
if item not in old_json[key]:
|
||||
old_json[key].append(item)
|
||||
else:
|
||||
old_json[key].extend(value)
|
||||
elif isinstance(value, dict):
|
||||
old_json[key] = merge_json(old_json.get(key, {}), value)
|
||||
else:
|
||||
old_json[key] = value
|
||||
# Erstelle eine Kopie des ersten JSON
|
||||
merged_data = json1.copy()
|
||||
|
||||
# Füge die Timestamps aus dem zweiten JSON ein, falls sie nicht bereits im ersten JSON vorhanden sind
|
||||
for timestamp, values in json2.items():
|
||||
if timestamp not in merged_data:
|
||||
merged_data[timestamp] = values
|
||||
|
||||
return merged_data
|
||||
|
||||
return old_json
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user