lcoulon Posted October 22, 2024 Posted October 22, 2024 Hello, I trying to run a py script from a server (192.168.0.10) to export current day production and consumption data from Shelly Pro 3EM (192.168.0.73) The script is hosted by local Raspberry server, hower when trying to run the script a syntaxe error is reported on that line : Quote root@RASPBX:/home/shelly# python3 /home/shelly/export_shelly_data.py File "/home/shelly/export_shelly_data.py", line 19 response = requests.get(f'http://{shelly_ip}/status') ^ SyntaxError: invalid syntax import requests import csv from datetime import datetime from ftplib import FTP # Configuration shelly_ip = "192.168.0.73" # Shelly Pro 3EM IP ftp_server = "192.168.0.10" ftp_user = "user" ftp_password = "password" ftp_directory = "/1Tb/Shelly_data_export" # Retrieve data from Shelly Pro 3EM response = requests.get(f'http://{shelly_ip}/status') response = requests.get(f'http://{shelly_ip}/rpc/Shelly.GetComponents'); components = response.json() data = response.json() # Data Extraction production = data['emeters'][0]['total'] consumption = data['emeters'][1]['total'] # CSV file generation filename = f'data_{datetime.now().strftime("%Y-%m-%d")}.csv' with open(filename, mode='w', newline='') as file: writer = csv.writer(file) writer.writerow(['Date', 'Production', 'Consommation']) writer.writerow([datetime.now().strftime("%Y-%m-%d"), production, consumption]) # Send CSV to FTP server ftp = FTP(ftp_server) ftp.login(ftp_user, ftp_password) ftp.cwd(ftp_directory) with open(filename, 'rb') as file: ftp.storbinary(f'STOR {filename}', file) ftp.quit() print(f'Fichier {filename} successfully sent over FTP.') Can someone tell what is wrong with that script ? Regards, Quote Translate Revert translation? English (American) French German Italian Polish Portuguese (European) Spanish
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.