Add type hints
This commit is contained in:
@@ -23,7 +23,7 @@ class Config(object):
|
|||||||
|
|
||||||
return yconfig
|
return yconfig
|
||||||
|
|
||||||
def reload(self):
|
def reload(self) -> None:
|
||||||
yconfig = self._load_config()
|
yconfig = self._load_config()
|
||||||
logging.config.dictConfig(yconfig["logging"])
|
logging.config.dictConfig(yconfig["logging"])
|
||||||
self.GROUPS = yconfig["groups"]["enable"]
|
self.GROUPS = yconfig["groups"]["enable"]
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ class Chengyu(object):
|
|||||||
|
|
||||||
return cys, zis, yins
|
return cys, zis, yins
|
||||||
|
|
||||||
def isChengyu(self, cy):
|
def isChengyu(self, cy: str) -> bool:
|
||||||
return self.cys.get(cy, None) is not None
|
return self.cys.get(cy, None) is not None
|
||||||
|
|
||||||
def getNext(self, cy, tongyin=True) -> str:
|
def getNext(self, cy: str, tongyin: bool = True) -> str:
|
||||||
"""获取下一个成语
|
"""获取下一个成语
|
||||||
cy: 当前成语
|
cy: 当前成语
|
||||||
tongyin: 是否允许同音字
|
tongyin: 是否允许同音字
|
||||||
@@ -56,7 +56,7 @@ class Chengyu(object):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def getMeaning(self, cy):
|
def getMeaning(self, cy: str) -> str:
|
||||||
ress = self.df[self.df["chengyu"] == cy].to_dict(orient="records")
|
ress = self.df[self.df["chengyu"] == cy].to_dict(orient="records")
|
||||||
if ress:
|
if ress:
|
||||||
res = ress[0]
|
res = ress[0]
|
||||||
|
|||||||
13
job_mgmt.py
13
job_mgmt.py
@@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
import schedule
|
import schedule
|
||||||
|
from typing import Any, Callable
|
||||||
|
|
||||||
|
|
||||||
class Job(object):
|
class Job(object):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def onEverySeconds(self, seconds, task, *args, **kwargs):
|
def onEverySeconds(self, seconds: int, task: Callable[..., Any], *args, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
每 seconds 秒执行
|
每 seconds 秒执行
|
||||||
:param seconds: 间隔,秒
|
:param seconds: 间隔,秒
|
||||||
@@ -17,7 +18,7 @@ class Job(object):
|
|||||||
"""
|
"""
|
||||||
schedule.every(seconds).seconds.do(task, *args, **kwargs)
|
schedule.every(seconds).seconds.do(task, *args, **kwargs)
|
||||||
|
|
||||||
def onEveryMinutes(self, minutes, task, *args, **kwargs):
|
def onEveryMinutes(self, minutes: int, task: Callable[..., Any], *args, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
每 minutes 分钟执行
|
每 minutes 分钟执行
|
||||||
:param minutes: 间隔,分钟
|
:param minutes: 间隔,分钟
|
||||||
@@ -26,7 +27,7 @@ class Job(object):
|
|||||||
"""
|
"""
|
||||||
schedule.every(minutes).minutes.do(task, *args, **kwargs)
|
schedule.every(minutes).minutes.do(task, *args, **kwargs)
|
||||||
|
|
||||||
def onEveryHours(self, hours, task, *args, **kwargs):
|
def onEveryHours(self, hours: int, task: Callable[..., Any], *args, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
每 hours 小时执行
|
每 hours 小时执行
|
||||||
:param hours: 间隔,小时
|
:param hours: 间隔,小时
|
||||||
@@ -35,7 +36,7 @@ class Job(object):
|
|||||||
"""
|
"""
|
||||||
schedule.every(hours).hours.do(task, *args, **kwargs)
|
schedule.every(hours).hours.do(task, *args, **kwargs)
|
||||||
|
|
||||||
def onEveryDays(self, days, task, *args, **kwargs):
|
def onEveryDays(self, days: int, task: Callable[..., Any], *args, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
每 days 天执行
|
每 days 天执行
|
||||||
:param days: 间隔,天
|
:param days: 间隔,天
|
||||||
@@ -44,7 +45,7 @@ class Job(object):
|
|||||||
"""
|
"""
|
||||||
schedule.every(days).days.do(task, *args, **kwargs)
|
schedule.every(days).days.do(task, *args, **kwargs)
|
||||||
|
|
||||||
def onEveryTime(self, times, task, *args, **kwargs):
|
def onEveryTime(self, times: int, task: Callable[..., Any], *args, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
每天定时执行
|
每天定时执行
|
||||||
:param times: 时间字符串列表,格式:
|
:param times: 时间字符串列表,格式:
|
||||||
@@ -62,7 +63,7 @@ class Job(object):
|
|||||||
for t in times:
|
for t in times:
|
||||||
schedule.every(1).days.at(t).do(task, *args, **kwargs)
|
schedule.every(1).days.at(t).do(task, *args, **kwargs)
|
||||||
|
|
||||||
def runPendingJobs(self):
|
def runPendingJobs(self) -> None:
|
||||||
schedule.run_pending()
|
schedule.run_pending()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user