- Removed obsolete script `script_SANSDEMARRAGE.sh`. - Added new `Camera.py` and `Connexion.py` files for camera handling and socket communication. - Implemented `First_Try.py` for initial camera preview testing. - Created `Humidity.py` for humidity sensor data acquisition. - Developed `Send_data_stocked.py` for managing and sending stored data. - Introduced `Time_Lapse_Connection.py` and `Time_Lapse_NoConnection.py` for connected and offline modes. - Added `get_from_server.py` for retrieving camera status from the server. - Updated `sync_offline_data.py` for synchronizing offline data. - Created `timelapse.service` for managing the timelapse service on Raspberry Pi. - Established package structure with `__init__.py` and `api_client.py` for API interactions. - Enhanced `capture.py` for managing image captures and data storage. - Configured `config.py` for centralized configuration management. - Developed `sensors.py` for handling environmental sensors and camera operations. - Implemented `timelapse_offline.py` and `timelapse_online.py` for capturing images in offline and online modes.
73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
import os
|
|
import requests
|
|
import shutil
|
|
import json
|
|
|
|
class Send_data_stocked:
|
|
def __init__(self):
|
|
self.url = "https://timelapse.kerboul.me/api/camera/upload"
|
|
self.headers = {
|
|
'accept': 'application/json'
|
|
}
|
|
self.project_path = "//home//timelapse//Documents//Time_Lapse//PROJECT//"
|
|
|
|
def get_list_folder(self,path = "//home//timelapse//Documents//Time_Lapse//PROJECT"):
|
|
# Liste des noms de dossiers
|
|
noms_dossiers = [nom for nom in os.listdir(path) if os.path.isdir(os.path.join(path, nom))]
|
|
print("Noms des dossiers :", noms_dossiers)
|
|
return noms_dossiers
|
|
|
|
def send_ALL_data_stocked(self):
|
|
tab_files = self.get_list_folder()
|
|
for i in tab_files:
|
|
self.send_data_stocked(i)
|
|
|
|
def send_data_stocked(self,file_name):
|
|
file_path = self.project_path + file_name + "//" + file_name
|
|
json_file_path = file_path + ".json"
|
|
img_file_path = file_path + ".jpg"
|
|
|
|
datas = self.get_json(json_file_path)
|
|
print(datas)
|
|
answer_from_server = self.upload_measurement(img_file_path, datas["timestamp"], datas["temperature"], datas["humidity"])
|
|
print(answer_from_server)
|
|
if (answer_from_server["message"]== "Mesure téléchargée avec succès"):
|
|
self.del_Folder(datas["timestamp"])
|
|
|
|
def get_json(self, file_path):
|
|
with open(file_path, "r", encoding='utf-8') as file:
|
|
datas = json.load(file)
|
|
return datas
|
|
return False
|
|
|
|
def del_Folder(self, name):
|
|
shutil.rmtree(self.project_path + name)
|
|
|
|
def upload_measurement(self, image_path, timestamp, temperature, humidity):
|
|
|
|
data = {
|
|
'timestamp': timestamp,
|
|
'temperature': temperature,
|
|
'humidity': humidity
|
|
}
|
|
files = {
|
|
'image': (image_path, open(image_path, 'rb'), 'image/jpeg')
|
|
}
|
|
try:
|
|
#print(data)
|
|
#print(files)
|
|
response = requests.post(self.url, headers=self.headers, data=data, files=files)
|
|
print(response)
|
|
response.raise_for_status()
|
|
response_data = response.json()
|
|
return response_data
|
|
except requests.exceptions.HTTPError as http_err:
|
|
print(f"HTTP error occurred: {http_err}")
|
|
except Exception as err:
|
|
print(f"Other error occurred: {err}")
|
|
|
|
if __name__ == "__main__":
|
|
SDS = Send_data_stocked()
|
|
#a = SDS.get_list_folder()[0]
|
|
SDS.send_ALL_data_stocked()
|