@@ -30,7 +30,7 @@ def lunar_month_day(today: date) -> str | None:
3030 day = solar_day (today )
3131 if day .isLunarLeap ():
3232 return None
33- return f' { day .getLunarMonth ():02d} -{ day .getLunarDay ():02d} '
33+ return f" { day .getLunarMonth ():02d} -{ day .getLunarDay ():02d} "
3434
3535
3636def solar_term_name (today : date ) -> str | None :
@@ -41,24 +41,24 @@ def solar_term_name(today: date) -> str | None:
4141
4242
4343def holiday_matches (holiday : dict , today : date ) -> bool :
44- if any (date_value in (today .strftime (' %m-%d' ), today .isoformat ()) for date_value in holiday .get (' dates' ) or ()):
44+ if any (date_value in (today .strftime (" %m-%d" ), today .isoformat ()) for date_value in holiday .get (" dates" ) or ()):
4545 return True
46- lunar_dates = holiday .get (' lunar' ) or ()
46+ lunar_dates = holiday .get (" lunar" ) or ()
4747 if lunar_dates :
4848 lunar_date = lunar_month_day (today )
4949 if lunar_date and lunar_date in lunar_dates :
5050 return True
51- terms = holiday .get (' jieqi' ) or ()
51+ terms = holiday .get (" jieqi" ) or ()
5252 if terms :
5353 solar_term = solar_term_name (today )
5454 if solar_term and solar_term in terms :
5555 return True
56- yearday = holiday .get (' yearday' )
56+ yearday = holiday .get (" yearday" )
5757 return yearday is not None and today .timetuple ().tm_yday == yearday
5858
5959
6060def match_holiday (config : dict , today : date ) -> dict | None :
61- for holiday in config .get (' holidays' ) or ():
61+ for holiday in config .get (" holidays" ) or ():
6262 if holiday_matches (holiday , today ):
6363 return holiday
6464 return None
@@ -67,9 +67,9 @@ def match_holiday(config: dict, today: date) -> dict | None:
6767def pick_pool (config : dict , today : date ) -> tuple [list [str ], str | None ]:
6868 holiday = match_holiday (config , today )
6969 if holiday :
70- return list (holiday .get (' descriptions' ) or ()), holiday .get (' name' ) or ' holiday'
71- core = list (config .get (' core' ) or ())
72- extras = config .get (' extras' )
70+ return list (holiday .get (" descriptions" ) or ()), holiday .get (" name" ) or " holiday"
71+ core = list (config .get (" core" ) or ())
72+ extras = config .get (" extras" )
7373 extras = list (extras ) if isinstance (extras , list ) else []
7474 if core and extras :
7575 pool = core if random .random () < 0.7 else extras
@@ -87,46 +87,46 @@ def resolve_today(timezone: str, date_override: str) -> date:
8787
8888
8989def write_github_output (description : str , holiday_name : str | None , today : date ) -> None :
90- path = os .environ .get (' GITHUB_OUTPUT' )
90+ path = os .environ .get (" GITHUB_OUTPUT" )
9191 if not path :
9292 return
93- with open (path , 'a' , encoding = ' utf-8' ) as output_file :
94- output_file .write (' description<<EOF\n ' )
95- output_file .write (f' { description } \n ' )
96- output_file .write (' EOF\n ' )
97- output_file .write (f' holiday={ holiday_name or "" } \n ' )
98- output_file .write (f' date={ today .isoformat ()} \n ' )
93+ with open (path , "a" , encoding = " utf-8" ) as output_file :
94+ output_file .write (" description<<EOF\n " )
95+ output_file .write (f" { description } \n " )
96+ output_file .write (" EOF\n " )
97+ output_file .write (f" holiday={ holiday_name or '' } \n " )
98+ output_file .write (f" date={ today .isoformat ()} \n " )
9999
100100
101101def main (arguments : list [str ] | None = None ) -> int :
102102 arguments = list (sys .argv [1 :] if arguments is None else arguments )
103103 if len (arguments ) < 1 :
104- print (' usage: pick.py <config.json> [timezone] [YYYY-MM-DD]' , file = sys .stderr )
104+ print (" usage: pick.py <config.json> [timezone] [YYYY-MM-DD]" , file = sys .stderr )
105105 return 2
106106 config_path = arguments [0 ]
107- timezone = arguments [1 ] if len (arguments ) > 1 and arguments [1 ] else ' Asia/Shanghai'
108- date_override = arguments [2 ] if len (arguments ) > 2 else ''
107+ timezone = arguments [1 ] if len (arguments ) > 1 and arguments [1 ] else " Asia/Shanghai"
108+ date_override = arguments [2 ] if len (arguments ) > 2 else ""
109109
110- with open (config_path , encoding = ' utf-8' ) as config_file :
110+ with open (config_path , encoding = " utf-8" ) as config_file :
111111 config = json5 .load (config_file )
112112
113113 today = resolve_today (timezone , date_override )
114114 pool , holiday_name = pick_pool (config , today )
115115 if not pool :
116- print (f' No descriptions available for today ({ today .isoformat ()} )' , file = sys .stderr )
116+ print (f" No descriptions available for today ({ today .isoformat ()} )" , file = sys .stderr )
117117 return 1
118118 description = random .choice (pool )
119119 if len (description ) > 350 :
120- print (f' Description exceeds 350 characters ({ len (description )} )' , file = sys .stderr )
120+ print (f" Description exceeds 350 characters ({ len (description )} )" , file = sys .stderr )
121121 return 1
122122
123123 write_github_output (description , holiday_name , today )
124- print (f' date={ today .isoformat ()} ' , file = sys .stderr )
124+ print (f" date={ today .isoformat ()} " , file = sys .stderr )
125125 if holiday_name :
126- print (f' holiday={ holiday_name } ' , file = sys .stderr )
127- print (f' description={ description } ' , file = sys .stderr )
126+ print (f" holiday={ holiday_name } " , file = sys .stderr )
127+ print (f" description={ description } " , file = sys .stderr )
128128 return 0
129129
130130
131- if __name__ == ' __main__' :
131+ if __name__ == " __main__" :
132132 raise SystemExit (main ())
0 commit comments