mirror of
https://github.com/Sneed-Group/Poodletooth-iLand
synced 2024-12-28 14:12:52 -06:00
29 lines
929 B
Python
29 lines
929 B
Python
import json
|
|
import os
|
|
|
|
|
|
class BackupManager:
|
|
def __init__(self, filepath='backups/', extension='.json'):
|
|
self.filepath = filepath
|
|
self.extension = extension
|
|
|
|
def getFileName(self, category, info):
|
|
filename = os.path.join(self.filepath, category) + '/'
|
|
for i in info:
|
|
filename += str(i) + '_'
|
|
return filename[:-1] + self.extension
|
|
|
|
def load(self, category, info, default=None):
|
|
filename = self.getFileName(category, info)
|
|
if not os.path.exists(filename):
|
|
return default
|
|
with open(filename, 'r') as f:
|
|
return json.load(f)
|
|
|
|
def save(self, category, info, data):
|
|
filepath = os.path.join(self.filepath, category)
|
|
if not os.path.exists(filepath):
|
|
os.makedirs(filepath)
|
|
filename = self.getFileName(category, info)
|
|
with open(filename, 'w') as f:
|
|
json.dump(data, f)
|