initial
This commit is contained in:
parent
04da522b64
commit
bb5453b59e
7 changed files with 451 additions and 1 deletions
25
common.py
Normal file
25
common.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import json
|
||||
import os
|
||||
|
||||
data_dir = 'prefetched'
|
||||
|
||||
|
||||
def get_data(name):
|
||||
file_path = os.path.join(data_dir, f"{name}.json")
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
data = json.load(file)
|
||||
return data
|
||||
except FileNotFoundError:
|
||||
return f"File {name}.json not found."
|
||||
except json.JSONDecodeError:
|
||||
return f"Error decoding JSON from {name}.json."
|
||||
|
||||
|
||||
def save_data(data, name):
|
||||
os.makedirs(data_dir, exist_ok=True)
|
||||
|
||||
file_path = os.path.join(data_dir, f"{name}.json")
|
||||
with open(file_path, 'w') as file:
|
||||
json.dump(data, file, indent=4)
|
||||
return f"Data saved to {name}.json."
|
||||
Loading…
Add table
Add a link
Reference in a new issue