Async, locale support, kill function changed
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Some set of functions needed for discord/telegram bots and other types of apps"""
|
||||
|
||||
from os import sep, stat, makedirs
|
||||
from os import sep, stat, makedirs, kill
|
||||
from os import name as osname
|
||||
from datetime import datetime
|
||||
from ujson import loads, dumps
|
||||
from shutil import copyfileobj
|
||||
from gzip import open as gzipopen
|
||||
from psutil import Process
|
||||
|
||||
|
||||
def nowtimeGet(format="%H:%M:%S | %d.%m.%Y"):
|
||||
@@ -103,4 +105,18 @@ def jsonLoad(filename):
|
||||
with open(filename, 'r', encoding="utf-8") as f:
|
||||
value = loads(f.read())
|
||||
f.close()
|
||||
return value
|
||||
return value
|
||||
|
||||
|
||||
def killProc(pid: int):
|
||||
"""Kill the process by its PID
|
||||
|
||||
Args:
|
||||
* pid (int): Process ID to be killed
|
||||
"""
|
||||
if osname == "posix":
|
||||
from signal import SIGKILL
|
||||
kill(pid, SIGKILL)
|
||||
else:
|
||||
p = Process(pid)
|
||||
p.kill()
|
@@ -56,15 +56,12 @@ def locale(key: str, *args: str, locale=configGet("locale")):
|
||||
locale = configGet("locale")
|
||||
|
||||
try:
|
||||
this_dict = jsonLoad(f'{configGet("locale", "locations")}{sep}{locale}.json')
|
||||
this_dict = jsonLoad(f'locale{sep}{locale}.json')
|
||||
except FileNotFoundError:
|
||||
try:
|
||||
this_dict = jsonLoad(f'{configGet("locale", "locations")}{sep}{configGet("locale")}.json')
|
||||
this_dict = jsonLoad(f'locale{sep}{configGet("locale")}.json')
|
||||
except FileNotFoundError:
|
||||
try:
|
||||
this_dict = jsonLoad(f'{configGet("locale_fallback", "locations")}{sep}{configGet("locale")}.json')
|
||||
except:
|
||||
return f'⚠️ Locale in config is invalid: could not get "{key}" in {str(args)} from locale "{locale}"'
|
||||
return f'⚠️ Locale in config is invalid: could not get "{key}" in {str(args)} from locale "{locale}"'
|
||||
|
||||
this_key = this_dict
|
||||
for dict_key in args:
|
||||
|
Reference in New Issue
Block a user