Weiterarbeit Users, Server implementier für Config-Data austausch, Data funktioniert noch nicht korrekt
This commit is contained in:
@@ -1,23 +1,30 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
def get_config(token_id):
|
||||
url = 'http://localhost:5000/getconfig'
|
||||
headers = {'ID': token_id}
|
||||
response = requests.post(url, headers=headers)
|
||||
|
||||
def update_config_on_server(token, config):
|
||||
## For developement now just return json from here
|
||||
with open("config.txt", 'r') as file:
|
||||
json_data = file.read()
|
||||
|
||||
return json_data
|
||||
|
||||
|
||||
## For server later
|
||||
response = requests.post(f'http://your_server_ip:5000/update_config?token={token}', json=config)
|
||||
if response.status_code == 200:
|
||||
print('Config updated successfully.')
|
||||
return response.json()
|
||||
else:
|
||||
print('Failed to update config.')
|
||||
return response
|
||||
return {'error': f'Request failed with status code {response.status_code}'}
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Beispiel für die Verwendung der Funktion update_config_on_server
|
||||
token = 'your_token'
|
||||
config = {'key1': 'new_value1', 'key2': 'new_value2'}
|
||||
update_config_on_server(token, config)
|
||||
def set_data(token_id, data):
|
||||
url = 'http://localhost:5000/setdata'
|
||||
headers = {'ID': token_id, 'JSON': json.dumps(data)}
|
||||
response = requests.post(url, headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
return {'message': 'Data sent successfully'}
|
||||
else:
|
||||
return {'error': f'Request failed with status code {response.status_code}'}
|
||||
|
||||
# Beispielaufrufe:
|
||||
# config = get_config('token123')
|
||||
# print(config)
|
||||
|
||||
# new_data = {'timestamps': ['2024-04-18 13:31', '2024-04-18 13:32'], 'Producer_sum': {'values': {'success': [True, True], 'day_energy': [6386, 6458], ...}}}
|
||||
# response = set_data('token123', new_data)
|
||||
# print(response)
|
||||
|
||||
Reference in New Issue
Block a user