Update API

This commit is contained in:
Burak
2024-02-16 11:11:24 +01:00
parent 54139a803e
commit 4d55f8a366
8 changed files with 181 additions and 75 deletions

View File

@@ -10,8 +10,8 @@ def database_connect():
database="goodgarden"
)
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}"
@@ -29,7 +29,7 @@ def fetch_and_display_all(urls, access_token):
# Wait for a certain time (e.g., 60 seconds) before making the next call
print("Waiting for the next retrieval action...")
time.sleep(10) # Time here is in seconds.
time.sleep(1) # Time here is in seconds.
def load_data(data):
mydb = database_connect()
@@ -62,10 +62,9 @@ def load_data(data):
print("Data inserted into the database.")
if __name__ == "__main__":
urls = [
"https://garden.inajar.nl/api/par_events/?format=json"
]
url = "https://garden.inajar.nl/api/par_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" # Vervang dit met jouw echte toegangstoken
fetch_and_display_all(urls, access_token)
fetch_and_display_all(url, access_token, repeat_count)