Input Velden Electron

This commit is contained in:
Atilla
2024-02-16 17:19:52 +01:00
23 changed files with 1957 additions and 269 deletions

View File

@@ -3,10 +3,8 @@ import time
from db_connect import database_connect
# connection = database_connect()
def fetch_and_display_all(urls, access_token):
for url in urls:
def fetch_and_display_all(url, access_token, repeat_count=5):
for _ in range(repeat_count):
try:
headers = {
"Authorization": f"Token {access_token}"
@@ -23,7 +21,9 @@ def fetch_and_display_all(urls, access_token):
print(f"Error fetching data from {url}: {e}")
print("Waiting for the next retrieval action...")
time.sleep(300) # Time here is in seconds.
time.sleep(1) # Time here is in seconds.
def load_data(data):
mydb = database_connect()
@@ -32,7 +32,7 @@ def load_data(data):
# Here you need to adjust the correct column names and data formats based on the API response
insert_query = """
INSERT INTO goodgarden.soil_relative_permittivity_events (timestamp, gateway_receive_time, device, value)
INSERT INTO goodgarden.soil_temperature_events (timestamp, gateway_receive_time, device, value)
VALUES (%s, %s, %s, %s)
"""
for record in data['results']:
@@ -56,10 +56,11 @@ def load_data(data):
print("Data inserted into the database.")
if __name__ == "__main__":
urls = [
"https://garden.inajar.nl/api/soil_relative_permittivity_events/?format=json"
]
url = "https://garden.inajar.nl/api/soil_relative_permittivity_events/?format=json"
access_token = "33bb3b42452306c58ecedc3c86cfae28ba22329c"
# You can change the repeat_count to control how many times you want to repeat the process
repeat_count = 10
access_token = "33bb3b42452306c58ecedc3c86cfae28ba22329c"
fetch_and_display_all(urls, access_token)
# fetch_and_display_all(urls, access_token)
fetch_and_display_all(url, access_token, repeat_count)