chore: totally fix lint issues
This commit is contained in:
@@ -1,36 +1,41 @@
|
||||
# 解小黑屋实现
|
||||
# 仍十分不完善,不建议使用
|
||||
|
||||
from Config import *
|
||||
from API_TitleServer import *
|
||||
from GetPreview import apiGetUserPreview
|
||||
from HelperLogInOut import apiLogout
|
||||
import rapidjson as json
|
||||
from loguru import logger
|
||||
import time
|
||||
from datetime import datetime
|
||||
import asyncio
|
||||
|
||||
import rapidjson as json
|
||||
|
||||
from GetPreview import apiGetUserPreview
|
||||
from HelperLogInOut import apiLogout
|
||||
from loguru import logger
|
||||
|
||||
from MyConfig import testUid2
|
||||
|
||||
|
||||
def isUserLoggedIn(userId):
|
||||
isLogin = json.loads(apiGetUserPreview(userId, True))['isLogin']
|
||||
isLogin = json.loads(apiGetUserPreview(userId, True))["isLogin"]
|
||||
logger.debug(f"用户 {userId} 是否登录: {isLogin}")
|
||||
return isLogin
|
||||
|
||||
|
||||
def getHumanReadableTime(unixTime):
|
||||
'''将 Unix 时间戳转换为人类可读的时间'''
|
||||
"""将 Unix 时间戳转换为人类可读的时间"""
|
||||
# 减一个小时,因为舞萌貌似是 UTC+9
|
||||
timestamp = int(unixTime) - 3600
|
||||
return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
|
||||
return datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
def getMaimaiUNIXTime(mmddhhmmss, year=2025):
|
||||
"""
|
||||
解析用户输入的 MMDDHHMMSS 格式的时间,返回 Unix 时间戳
|
||||
时间会被推后一个小时,因为舞萌貌似是 UTC+9?
|
||||
"""
|
||||
#date_time_str = f"{year}{mmddhhmmss}"
|
||||
# date_time_str = f"{year}{mmddhhmmss}"
|
||||
# 加上一个小时
|
||||
date_time_str = f"{year}{mmddhhmmss[:4]}{int(mmddhhmmss[4:6])+1:02}{mmddhhmmss[6:]}"
|
||||
date_time_obj = datetime.strptime(date_time_str, '%Y%m%d%H%M%S')
|
||||
date_time_str = (
|
||||
f"{year}{mmddhhmmss[:4]}{int(mmddhhmmss[4:6]) + 1:02}{mmddhhmmss[6:]}"
|
||||
)
|
||||
date_time_obj = datetime.strptime(date_time_str, "%Y%m%d%H%M%S")
|
||||
# 将 datetime 对象转换为 Unix 时间戳
|
||||
unix_timestamp = int(time.mktime(date_time_obj.timetuple()))
|
||||
logger.info(f"转换出了时间戳: {unix_timestamp}")
|
||||
@@ -41,19 +46,20 @@ def logOut(userId, Timestamp):
|
||||
"""极其简单的登出实现,成功返回 True,失败返回 False
|
||||
注意:不会检查用户是否真的登出了,只会尝试登出"""
|
||||
try:
|
||||
if apiLogout(Timestamp, userId, True)['returnCode'] == 1:
|
||||
if apiLogout(Timestamp, userId, True)["returnCode"] == 1:
|
||||
# 成功送出了登出请求
|
||||
logger.debug(f"已成功尝试登出用户 {userId}")
|
||||
return True
|
||||
except:
|
||||
except Exception:
|
||||
logger.error(f"登出用户 {userId} 的时候发生了错误")
|
||||
return False
|
||||
|
||||
|
||||
def isCorrectTimestamp(timestamp, userId):
|
||||
'''
|
||||
"""
|
||||
动作:给定一个时间戳,用它尝试登出用户,然后检查用户是否成功登出。
|
||||
如果用户成功登出,返回 True;否则返回 False。
|
||||
'''
|
||||
"""
|
||||
if not logOut(userId, timestamp):
|
||||
logger.error(f"用时间戳 {timestamp} 登出用户 {userId} 的时候发生了错误")
|
||||
return False
|
||||
@@ -61,6 +67,7 @@ def isCorrectTimestamp(timestamp, userId):
|
||||
logger.debug(f"时间戳 {timestamp} 是否正确: {isLoggedOut}")
|
||||
return isLoggedOut
|
||||
|
||||
|
||||
def findCorrectTimestamp(timestamp, userId, max_attempts=600):
|
||||
# 初始化偏移量
|
||||
offset = 1
|
||||
@@ -72,19 +79,19 @@ def findCorrectTimestamp(timestamp, userId, max_attempts=600):
|
||||
if isCorrectTimestamp(currentTryTimestamp, userId):
|
||||
logger.info(f"正确的时间戳: {currentTryTimestamp}")
|
||||
return currentTryTimestamp
|
||||
|
||||
|
||||
# 增加偏移量尝试
|
||||
currentTryTimestamp = timestamp + offset
|
||||
if isCorrectTimestamp(currentTryTimestamp, userId):
|
||||
logger.info(f"正确的时间戳(在给定时间以后): {currentTryTimestamp}")
|
||||
return currentTryTimestamp
|
||||
|
||||
|
||||
# 减少偏移量尝试
|
||||
currentTryTimestamp = timestamp - offset
|
||||
if isCorrectTimestamp(currentTryTimestamp, userId):
|
||||
logger.info(f"正确的时间戳(在给定时间以前): {currentTryTimestamp}")
|
||||
return currentTryTimestamp
|
||||
|
||||
|
||||
# 增加尝试次数和偏移量
|
||||
attempts += 2
|
||||
offset += 1
|
||||
@@ -92,6 +99,7 @@ def findCorrectTimestamp(timestamp, userId, max_attempts=600):
|
||||
logger.error(f"无法找到正确的时间戳,尝试次数超过了 {max_attempts}")
|
||||
return None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
human_time = "0207155500"
|
||||
beginTimestamp = getMaimaiUNIXTime(human_time)
|
||||
|
||||
Reference in New Issue
Block a user