Caching ClearSky requests

Signed-off-by: Markus Birth <markus@birth-online.de>
This commit is contained in:
2026-05-13 13:33:56 +01:00
parent 2f7663117c
commit 0200e22eb5
+10 -2
View File
@@ -1,4 +1,5 @@
import configparser
import json
import requests
import os.path
import pickle
@@ -65,8 +66,15 @@ class ClearSky():
url = self.BASE_URL + "/api/v1/" + uri
if page > 1:
url += f"/{page}"
r = requests.get(url).json()
sleep(0.20) # Poor man's way of making sure to not go over 5 requests per second
cachefile = "cs_" + url[len(self.BASE_URL)+8:].replace("/", "_") + ".json"
if os.path.isfile(cachefile):
with open(cachefile, "rt") as f:
r = json.load(f)
else:
r = requests.get(url).json()
with open(cachefile, "wt") as f:
json.dump(r, f)
sleep(0.20) # Poor man's way of making sure to not go over 5 requests per second
data_len = len(r["data"][data_key]) if data_key else len(r["data"])
result += r["data"][data_key] if data_key else r["data"]
if data_len < 100: