Skip to content

Commit c8087bf

Browse files
committed
Update index.py
1 parent 104a94c commit c8087bf

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

index.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def isLeapYear(year):
7474

7575

7676
# 判断day是否是month的最后一天
77-
def isLastDayOfMonth(month, day):
78-
if month == 2 and isLeapYear(YEAR):
79-
return day == leapDay
80-
return day == monthLastDayMapping[month]
77+
def isLastDayOfMonth(num_month, num_day):
78+
if num_month == 2 and isLeapYear(YEAR):
79+
return num_day == leapDay
80+
return num_day == monthLastDayMapping[num_month]
8181

8282

8383
if isLeapYear(YEAR):
@@ -101,7 +101,7 @@ def isLastDayOfMonth(month, day):
101101
festivals[month.zfill(2) + day.zfill(2)] = f[0]
102102

103103
# 在这里增加想要添加的节日,可以覆盖掉上面的节日
104-
festivals['0101'] = '元旦'
104+
# festivals['0101'] = '元旦'
105105

106106
res = []
107107
langs = []
@@ -110,8 +110,7 @@ def isLastDayOfMonth(month, day):
110110
codeLang = lang_json[langIndex]
111111
try:
112112
url = 'https://zh.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&uselang=zh-cn&titles=' + \
113-
quote(codeLang[
114-
'desc'], 'utf-8')
113+
quote(codeLang['desc'], 'utf-8')
115114
# 请求头部
116115
headers = {
117116
'User-Agent':
@@ -123,14 +122,13 @@ def isLastDayOfMonth(month, day):
123122
# 读取响应,获得文本
124123
wiki = json.loads(response.text)
125124
desc = jsonpath.jsonpath(wiki, '$..extract')
126-
codeLang['descWiki'] = desc[0].split('\n')[0]
125+
# codeLang['descWiki'] = desc[0].split('\n')[0]
126+
codeLang['descWiki'] = desc[0].split('。')[0] + "。"
127127
langIndex = langIndex + 1
128128
except Exception as e:
129-
print("!!!!!!!error!!!!!!!!!!", e)
129+
print("Error!", e)
130130
continue
131-
code_string = open('hacking-date/HackingDate.' + codeLang['code'],
132-
'r',
133-
encoding='utf8')
131+
code_string = open('hacking-date/HackingDate.' + codeLang['code'], 'r', encoding='utf8')
134132
# 对内容中的特殊符合进行转义,以在HTML中显示
135133
codeLang['code'] = html.escape(code_string.read())
136134
langs.append(codeLang)
@@ -213,6 +211,7 @@ def isLastDayOfMonth(month, day):
213211
rows = rows + '</tr>'
214212

215213
# 生成后面的7天一页的日历
214+
# noinspection PyUnboundLocalVariable
216215
if weekday == 0 or len(page) == 0:
217216
if PUNCHED:
218217
page = pageTemplate.replace('{{pclass}}', 'page punched')
@@ -231,6 +230,7 @@ def isLastDayOfMonth(month, day):
231230
)
232231
page = page.replace('{{main-week}}', f'{weeks[date.getWeek()]}')
233232
page = page.replace('{{mwclass}}', 'main-week')
233+
# noinspection DuplicatedCode
234234
if (str(date.getMonth()).zfill(2) + str(date.getDay()).zfill(2)
235235
in festivals.keys()):
236236
ldata = festivals[str(date.getMonth()).zfill(2) +
@@ -276,8 +276,7 @@ def isLastDayOfMonth(month, day):
276276

277277
page = page.replace('{{desc}}', langs[langIndex]['descWiki'])
278278
if QR:
279-
wiki_url = 'https://zh.wikipedia.org/wiki/' + quote(langs[langIndex][
280-
'desc'], 'utf-8')
279+
wiki_url = 'https://zh.wikipedia.org/wiki/' + quote(langs[langIndex]['desc'], 'utf-8')
281280
# qr = 'https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=' + wiki_url
282281
qr = 'https://chart.apis.google.com/chart?chs=360x360&cht=qr&choe=UTF-8&chld=M|0&chl=' + wiki_url
283282
else:
@@ -289,6 +288,7 @@ def isLastDayOfMonth(month, day):
289288
page = page.replace('{{wclass' + str(weekday + 1) + '}}', '')
290289
page = page.replace(f'{{{{date{weekday + 1}}}}}', # 此处用fstring时一定要注意{要进行转义
291290
str(date.getMonth()).zfill(2) + "-" + str(date.getDay()).zfill(2))
291+
# noinspection DuplicatedCode
292292
if (str(date.getMonth()).zfill(2) + str(date.getDay()).zfill(2)
293293
in festivals.keys()):
294294
ldata = festivals[str(date.getMonth()).zfill(2) +

0 commit comments

Comments
 (0)