Saving logs+data to dir. fixes
This commit is contained in:
@ -8,12 +8,18 @@ from logger import generalLogger
|
||||
import options
|
||||
|
||||
|
||||
jsonPath = 'data/data.json'
|
||||
|
||||
|
||||
def startUp():
|
||||
filePath = 'data.json'
|
||||
filePath = jsonPath
|
||||
|
||||
if not(os.path.exists('data')):
|
||||
os.mkdir('data')
|
||||
|
||||
if os.path.exists(filePath):
|
||||
timestamp = datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
|
||||
backupPath = (f'data_backup_{timestamp}.json')
|
||||
timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
|
||||
backupPath = (f'data/data_backup_{timestamp}.json')
|
||||
shutil.copy(filePath, backupPath)
|
||||
generalLogger.info(f'JSON backup was created: {backupPath}')
|
||||
|
||||
@ -47,10 +53,10 @@ async def checkPair(pair: str):
|
||||
# Returnes 1 if pair exists and 0 if not
|
||||
currentData = {}
|
||||
try:
|
||||
with open('data.json', 'r') as f:
|
||||
with open(jsonPath, 'r') as f:
|
||||
currentData = json.load(f)
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
generalLogger.info('WARNING: JSON file is empty! Ignore if your installation is fresh.')
|
||||
generalLogger.warning('JSON file is empty!')
|
||||
|
||||
if pair in currentData:
|
||||
return 1
|
||||
@ -61,14 +67,14 @@ async def deletePair(pair: str):
|
||||
# Returnes 0 if deleted successfully and -1 if not
|
||||
currentData = {}
|
||||
try:
|
||||
with open('data.json', 'r') as f:
|
||||
with open(jsonPath, 'r') as f:
|
||||
currentData = json.load(f)
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
generalLogger.info('WARNING: JSON file is empty! Ignore if your installation is fresh.')
|
||||
generalLogger.warning('JSON file is empty!')
|
||||
|
||||
if pair in currentData:
|
||||
del currentData[pair]
|
||||
with open('data.json', 'w', encoding = 'utf-8') as f:
|
||||
with open(jsonPath, 'w', encoding = 'utf-8') as f:
|
||||
json.dump(currentData, f, ensure_ascii = False, indent = 4)
|
||||
generalLogger.info(f'Pair {pair} was deleted successfully!')
|
||||
return 0
|
||||
@ -85,16 +91,16 @@ async def savePairParams(pair: str, params):
|
||||
|
||||
currentData = {}
|
||||
try:
|
||||
with open('data.json', 'r') as f:
|
||||
with open(jsonPath, 'r') as f:
|
||||
currentData = json.load(f)
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
generalLogger.info('WARNING: JSON file is empty! Ignore if your installation is fresh.')
|
||||
generalLogger.warning('JSON file is empty!')
|
||||
|
||||
if pair in currentData:
|
||||
generalLogger.info(f"Pair {pair} already exists.")
|
||||
return -2
|
||||
else:
|
||||
with open('data.json', 'w', encoding = 'utf-8') as f:
|
||||
with open(jsonPath, 'w', encoding = 'utf-8') as f:
|
||||
currentData.update(newData)
|
||||
json.dump(currentData, f, ensure_ascii = False, indent = 4)
|
||||
generalLogger.info(f"Pair {pair} was added!")
|
||||
@ -105,8 +111,8 @@ async def loadJson():
|
||||
# Returnes the contents of the JSON file as a dictionary
|
||||
data = {}
|
||||
try:
|
||||
with open('data.json', 'r') as f:
|
||||
with open(jsonPath, 'r') as f:
|
||||
data = json.load(f)
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
generalLogger.info('WARNING: JSON file is empty! Ignore if your installation is fresh.')
|
||||
generalLogger.warning('JSON file is empty!')
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user