1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2025-01-19 06:25:18 +00:00

Added dev utils to facilitate methods and file access

This commit is contained in:
Myned 2017-10-11 02:54:32 -04:00
parent 48e442b5a2
commit a99b9a9626

36
src/main/utils/utils.py Normal file
View file

@ -0,0 +1,36 @@
import json
try:
with open('background.json') as infile:
background = json.load(infile)
print('\"background.json\" loaded.')
except FileNotFoundError:
with open('background.json', 'w+') as iofile:
print('Background file not found: \"background.json\" created and loaded.')
json.dump({}, iofile, indent=4, sort_keys=True)
iofile.seek(0)
background = json.load(iofile)
with open('config.json') as infile:
config = json.load(infile)
def update(out, file):
with open(file, 'w') as outfile:
json.dump(out, outfile, indent=4, sort_keys=True)
import asyncio
async def clear(obj, interval=10*60, replace=None):
if replace is None:
if type(obj) is list:
replace = []
elif type(obj) is dict:
replace = {}
elif type(obj) is int:
replace = 0
elif type(obj) is str:
replace = ''
while True:
obj = replace
asyncio.sleep(interval)