mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-25 09:37:30 +00:00
🎨 Use ujson
to Convert Data
This commit is contained in:
parent
24ce0dac92
commit
16dfd5021e
@ -1,4 +1,3 @@
|
||||
import json
|
||||
from io import BytesIO
|
||||
|
||||
import genshin
|
||||
@ -39,6 +38,12 @@ from utils.helpers import get_genshin_client
|
||||
from utils.log import logger
|
||||
from utils.models.base import RegionEnum
|
||||
|
||||
try:
|
||||
import ujson as jsonlib
|
||||
|
||||
except ImportError:
|
||||
import json as jsonlib
|
||||
|
||||
INPUT_URL, INPUT_FILE, CONFIRM_DELETE = range(10100, 10103)
|
||||
|
||||
|
||||
@ -62,7 +67,7 @@ class GachaLogPlugin(Plugin.Conversation, BasePlugin.Conversation):
|
||||
async def __async_init__(self):
|
||||
await update_paimon_moe_zh(False)
|
||||
async with async_open(GACHA_LOG_PAIMON_MOE_PATH, "r", encoding="utf-8") as load_f:
|
||||
self.zh_dict = json.loads(await load_f.read())
|
||||
self.zh_dict = jsonlib.loads(await load_f.read())
|
||||
|
||||
async def _refresh_user_data(
|
||||
self, user: User, data: dict = None, authkey: str = None, verify_uid: bool = True
|
||||
@ -117,7 +122,7 @@ class GachaLogPlugin(Plugin.Conversation, BasePlugin.Conversation):
|
||||
await (await document.get_file()).download_to_memory(out=out)
|
||||
if file_type == "json":
|
||||
# bytesio to json
|
||||
data = json.loads(out.getvalue().decode("utf-8"))
|
||||
data = jsonlib.loads(out.getvalue().decode("utf-8"))
|
||||
elif file_type == "xlsx":
|
||||
data = self.gacha_log.convert_xlsx_to_uigf(out, self.zh_dict)
|
||||
else:
|
||||
|
@ -1,4 +1,3 @@
|
||||
import json
|
||||
from os import sep
|
||||
|
||||
from telegram import Update
|
||||
@ -12,6 +11,12 @@ from utils.decorators.error import error_callable
|
||||
from utils.decorators.restricts import restricts
|
||||
from utils.log import logger
|
||||
|
||||
try:
|
||||
import ujson as jsonlib
|
||||
|
||||
except ImportError:
|
||||
import json as jsonlib
|
||||
|
||||
|
||||
class HilichurlsPlugin(Plugin, BasePlugin):
|
||||
"""丘丘语字典."""
|
||||
@ -19,7 +24,7 @@ class HilichurlsPlugin(Plugin, BasePlugin):
|
||||
def __init__(self):
|
||||
"""加载数据文件.数据整理自 https://wiki.biligame.com/ys By @zhxycn."""
|
||||
with open(f"resources{sep}json{sep}hilichurls_dictionary.json", "r", encoding="utf8") as f:
|
||||
self.hilichurls_dictionary = json.load(f)
|
||||
self.hilichurls_dictionary = jsonlib.load(f)
|
||||
|
||||
@handler(CommandHandler, command="hilichurls", block=False)
|
||||
@restricts()
|
||||
|
@ -1,4 +1,3 @@
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import traceback
|
||||
@ -15,6 +14,12 @@ from core.plugin import Plugin, error_handler
|
||||
from modules.errorpush import PbClient, SentryClient, PbClientException, SentryClientException
|
||||
from utils.log import logger
|
||||
|
||||
try:
|
||||
import ujson as jsonlib
|
||||
|
||||
except ImportError:
|
||||
import json as jsonlib
|
||||
|
||||
notice_chat_id = bot.config.error.notification_chat_id
|
||||
current_dir = os.getcwd()
|
||||
logs_dir = os.path.join(current_dir, "logs")
|
||||
@ -52,7 +57,7 @@ class ErrorHandler(Plugin):
|
||||
|
||||
error_text = (
|
||||
f"-----Exception while handling an update-----\n"
|
||||
f"update = {json.dumps(update_str, indent=2, ensure_ascii=False)}\n"
|
||||
f"update = {jsonlib.dumps(update_str, indent=2, ensure_ascii=False)}\n"
|
||||
f"context.chat_data = {str(context.chat_data)}\n"
|
||||
f"context.user_data = {str(context.user_data)}\n"
|
||||
"\n"
|
||||
|
@ -1,5 +1,4 @@
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
from sys import executable
|
||||
|
||||
@ -15,6 +14,12 @@ from utils.decorators.admins import bot_admins_rights_check
|
||||
from utils.helpers import execute
|
||||
from utils.log import logger
|
||||
|
||||
try:
|
||||
import ujson as jsonlib
|
||||
|
||||
except ImportError:
|
||||
import json as jsonlib
|
||||
|
||||
current_dir = os.getcwd()
|
||||
|
||||
UPDATE_DATA = os.path.join(current_dir, "data", "update.json")
|
||||
@ -28,7 +33,7 @@ class UpdatePlugin(Plugin):
|
||||
async def __async_init__():
|
||||
if os.path.exists(UPDATE_DATA):
|
||||
async with async_open(UPDATE_DATA) as file:
|
||||
data = json.loads(await file.read())
|
||||
data = jsonlib.loads(await file.read())
|
||||
try:
|
||||
reply_text = Message.de_json(data, bot.app.bot)
|
||||
await reply_text.edit_text("重启成功")
|
||||
|
Loading…
Reference in New Issue
Block a user