-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
30 lines (23 loc) · 1002 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import cache_site
import config
import json
cache_site.initialized = True
def run():
try:
if 'cache' not in os.listdir(path="."):
os.mkdir("cache")
if 'data.txt' in os.listdir(path="./cache"):
# at this point, we know "cache folder" exists with previous data => both file name fields must be updated
config.prev_cache_file_name = "cache/data.txt"
prev_file_name_index = 0
while f"data({prev_file_name_index + 1}).txt" in os.listdir('cache'):
prev_file_name_index += 1
if prev_file_name_index > 0:
config.prev_cache_file_name = f"cache/data({prev_file_name_index}).txt"
config.next_cache_file_name = f"cache/data({prev_file_name_index + 1}).txt"
with open(config.prev_cache_file_name, mode='r') as prev_cache_file:
config.persistent_data = json.loads(prev_cache_file.read())
except OSError as e:
raise e
run()