Add a caching system in case where remote calendar is unreachable #1
1 changed files with 4 additions and 4 deletions
|
@ -21,11 +21,11 @@ def cache(entry: dict) -> None:
|
||||||
:type entry: dict
|
:type entry: dict
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not os.path.isdir('cache'):
|
if not os.path.isdir('app/cache'):
|
||||||
os.mkdir('cache')
|
os.mkdir('app/cache')
|
||||||
|
|
||||||
url = entry['url']
|
url = entry['url']
|
||||||
path = "cache/" + sha256(url.encode()).hexdigest() + ".ics"
|
path = "app/cache/" + sha256(url.encode()).hexdigest() + ".ics"
|
||||||
|
|
||||||
r = requests.get(entry["url"], allow_redirects=True)
|
r = requests.get(entry["url"], allow_redirects=True)
|
||||||
if "encoding" in entry:
|
if "encoding" in entry:
|
||||||
|
@ -54,7 +54,7 @@ def get_from_cache(entry: dict) -> Calendar:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
url = entry['url']
|
url = entry['url']
|
||||||
path = "cache/" + sha256(url.encode()).hexdigest() + ".ics"
|
path = "app/cache/" + sha256(url.encode()).hexdigest() + ".ics"
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
print("Not cached")
|
print("Not cached")
|
||||||
raise FileNotFoundError("The calendar is not cached")
|
raise FileNotFoundError("The calendar is not cached")
|
||||||
|
|
Loading…
Add table
Reference in a new issue