mirror of
https://github.com/myned/modufur.git
synced 2025-01-19 14:25:18 +00:00
Added dev utils to facilitate methods and file access
This commit is contained in:
parent
48e442b5a2
commit
a99b9a9626
1 changed files with 36 additions and 0 deletions
36
src/main/utils/utils.py
Normal file
36
src/main/utils/utils.py
Normal 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)
|
Loading…
Add table
Reference in a new issue