@@ -31,12 +31,12 @@ class ScriptTask(KU, KekkaiActivationAssets):
3131 def run (self ):
3232 con = self .config .kekkai_activation .activation_config
3333
34- # 日期过滤检查 (适合多个小号轮流挂卡给大号吃)
35- if con .activation_dates :
36- today = datetime .now ().day
37- allowed_dates = [ int ( d . strip ()) for d in con .activation_dates . split ( ',' ) if d . strip (). isdigit ()]
38- if today not in allowed_dates :
39- logger .info (f"今日日期 { today } 不在挂卡日期列表 { allowed_dates } 中,跳过挂卡任务" )
34+ # 星期过滤检查 (适合多个小号轮流挂卡给大号吃)
35+ if con .activation_weekdays :
36+ weekday = datetime .now ().weekday () # 0=周一, 6=周日
37+ allowed_weekdays = self . parse_weekdays ( con .activation_weekdays )
38+ if weekday not in allowed_weekdays :
39+ logger .info (f"今日星期 { weekday + 1 } 不在挂卡星期列表 { allowed_weekdays } 中,跳过挂卡任务" )
4040 # 设置下次执行时间为明天0点
4141 next_run = (datetime .now ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
4242 + timedelta (days = 1 ))
@@ -163,6 +163,41 @@ def run_activation(self, _config: ActivationConfig) -> bool:
163163 logger .info ('Card is not selected also not using' )
164164 self .screening_card (_config .card_type )
165165
166+ def parse_weekdays (self , weekdays_str : str ) -> list [int ]:
167+ """
168+ 解析星期配置,支持多种格式:
169+ - 中文:周一、周二、周三、周四、周五、周六、周日
170+ - 数字:1-7(1=周一,7=周日)
171+ - 分隔符:支持英文逗号(,)、中文逗号(,)、顿号(、)
172+ 返回:datetime.weekday() 格式(0=周一,6=周日)
173+ """
174+ weekday_map = {
175+ # 中文 -> weekday (0=周一)
176+ '周一' : 0 , '周二' : 1 , '周三' : 2 , '周四' : 3 , '周五' : 4 , '周六' : 5 , '周日' : 6 ,
177+ }
178+
179+ # 统一分隔符:将中文逗号和顿号都替换为英文逗号
180+ normalized_str = weekdays_str .replace (',' , ',' ).replace ('、' , ',' )
181+
182+ allowed_weekdays = []
183+ for item in normalized_str .split (',' ):
184+ item = item .strip ()
185+ if not item :
186+ continue
187+
188+ # 数字(1-7,1=周一)
189+ if item .isdigit ():
190+ weekday = int (item )
191+ if 1 <= weekday <= 7 :
192+ allowed_weekdays .append (weekday - 1 ) # 转换为 weekday 格式
193+ # 中文
194+ elif item in weekday_map :
195+ allowed_weekdays .append (weekday_map [item ])
196+ else :
197+ logger .warning (f"无法识别的星期配置:{ item } " )
198+
199+ return allowed_weekdays
200+
166201 def goto_cards (self ):
167202 """
168203 寮结界,前往挂卡界面
0 commit comments