Skip to content

修改并生成新文件 #4

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
29dd78c
Update README.md
lzcapp Jun 2, 2022
86e5826
Create .gitignore
lzcapp Jun 2, 2022
1b428b8
Update config.json
lzcapp Jun 2, 2022
f0a59c1
Create and move generated files
lzcapp Jun 2, 2022
d458742
Move generated files
lzcapp Jun 2, 2022
8a21d3e
Update README.md
lzcapp Jun 2, 2022
b87fc0f
Update README.md
lzcapp Jun 2, 2022
67f14dc
Set theme jekyll-theme-minimal
lzcapp Jun 3, 2022
2149af7
Set theme jekyll-theme-cayman
lzcapp Jun 3, 2022
994c2e7
Update README.md
lzcapp Nov 22, 2022
8c2b5a7
Modified the calendar page
lzcapp Nov 22, 2022
f8fd002
Remove and regenerate
lzcapp Nov 22, 2022
c084bf1
Update config.json
lzcapp Nov 22, 2022
90f9d95
Generate calendar for the year 2023
lzcapp Nov 22, 2022
855b2ea
Update README.md
lzcapp Nov 22, 2022
487e645
Update .gitignore
lzcapp Jul 13, 2023
5dc3a7c
Calendar-2024
lzcapp Jul 13, 2023
598bfb9
Update README.md
lzcapp Jul 13, 2023
cac5ccd
Update Calendar-2023.html
lzcapp Sep 11, 2023
9c624a6
Update html and pdf
lzcapp Jan 6, 2024
fd3064a
Add 2025 html and pdf
lzcapp Jan 6, 2024
6c8395e
Update README.md
lzcapp Jan 6, 2024
309707d
Update html and pdf
lzcapp Jan 6, 2024
b148035
Update cal.html
lzcapp Jan 6, 2024
271f949
Update page.html
lzcapp Jan 6, 2024
2c0099f
Regenerate html & pdf files
lzcapp Jan 8, 2024
104a94c
Update lang.json
lzcapp Jan 8, 2024
c8087bf
Update index.py
lzcapp Jan 8, 2024
4abaf42
Update README.md
lzcapp Jan 8, 2024
8c80195
Correct typo in comment
lzcapp Jan 24, 2024
6ce9394
Update index.py
lzcapp Nov 24, 2024
c791bc8
Update cal.css
lzcapp Nov 24, 2024
18aa186
Update calendar HTML & PDF
lzcapp Nov 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/.idea/**
**/build/**
**/dist/**
index.spec
Binary file removed Calendar-2021.pdf
Binary file not shown.
3,185 changes: 3,185 additions & 0 deletions Calendar-2022.html

Large diffs are not rendered by default.

Binary file added Calendar-2022.pdf
Binary file not shown.
2,085 changes: 1,069 additions & 1,016 deletions Calendar-2021.html → Calendar-2023.html

Large diffs are not rendered by default.

Binary file added Calendar-2023.pdf
Binary file not shown.
3,185 changes: 3,185 additions & 0 deletions Calendar-2024.html

Large diffs are not rendered by default.

Binary file added Calendar-2024.pdf
Binary file not shown.
3,185 changes: 3,185 additions & 0 deletions Calendar-2025.html

Large diffs are not rendered by default.

Binary file added Calendar-2025.pdf
Binary file not shown.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@

## 结果展示

HTML样式展示:[link](./Calendar-2021.html)
HTML样式展示:

PDF样式展示:[link](./Calendar-2021.pdf)
- [2022](https://github.lzc.app/OHHC-Python/Calendar-2022.html)
- [2023](https://github.lzc.app/OHHC-Python/Calendar-2023.html)
- [2024](https://github.lzc.app/OHHC-Python/Calendar-2024.html)
- [2025](https://github.lzc.app/OHHC-Python/Calendar-2025.html)

PDF样式展示:

- [2022](https://github.lzc.app/OHHC-Python/Calendar-2022.pdf)
- [2023](https://github.lzc.app/OHHC-Python/Calendar-2023.pdf)
- [2024](https://github.lzc.app/OHHC-Python/Calendar-2024.pdf)
- [2025](https://github.lzc.app/OHHC-Python/Calendar-2025.pdf)

## 环境依赖

Expand All @@ -23,6 +33,12 @@ Python 3 (Python 3.9.1)

除此之外,因为项目需要爬取维基百科中对编程语言的介绍,所以需要可以访问维基百科。

如遇`Caused by SSLError`错误,是urllib3版本的问题,可以换用 1.25.11或者其他低版本,在原环境中重装低版本urllib3:

```python
pip install urllib3==1.25.11
```

## 配置文件

在`config.json`中有以下参数可以配置:
Expand All @@ -34,6 +50,6 @@ Python 3 (Python 3.9.1)

## 运行

下载程序安装好环境运行index.py
下载程序安装好环境运行index.py

输出为类似`Calendar-2021.html`的文件
输出为`Calendar-[YYYY].html`,您可以用“打印”的方式将其转换为PDF格式文件。
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-cayman
19 changes: 16 additions & 3 deletions cal.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@
}

body {
font-family: 'Space Mono', monospace, 'Noto Serif SC', 'Noto Sans SC Sliced';
font-family: 'JetBrains Mono', 'JetBrains Mono';
font-feature-settings: "liga" 0;
font-size: 5mm;
}

.description {
font-family: 'JetBrains Mono', sans-serif;
}

.lunar {
font-family: 'JetBrains Mono', sans-serif;
}

.main-lunar {
font-family: 'JetBrains Mono', sans-serif;
}

.monthly h1 {
text-align: center;
}
Expand Down Expand Up @@ -159,7 +171,7 @@ body {
.page .description {
position: absolute;
width: 130mm;
bottom: 70mm;
bottom: 90mm;
color: #666;
text-align: justify;
font-size: 0.8em;
Expand Down Expand Up @@ -190,7 +202,7 @@ body {

.page ul.date {
width: 174.5mm;
height: 41mm;
height: 50mm;
position: absolute;
display: table;
left: 17.5mm;
Expand All @@ -211,6 +223,7 @@ body {
list-style: none;
display: table-cell;
height: 40mm;
width: 30mm;
border-left: 0.5mm dotted gray;
box-sizing: border-box;
vertical-align: top;
Expand Down
4 changes: 2 additions & 2 deletions cal.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html>
<html lang="zh-CN">
<head>
<link rel="stylesheet" href="cal.css">
<link rel="stylesheet"
Expand All @@ -14,7 +14,7 @@
<script>aSpace(document.getElementsByClassName('description'));</script>
<script>
hljs.initHighlightingOnLoad();
var prism = document.createElement('script');
let prism = document.createElement('script');
prism.src = 'prism.js';
document.body.appendChild(prism);
</script>
Expand Down
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"year": 2021,
"qr": true,
"year": 2023,
"qr": false,
"punched": false,
"monthly": true
}
32 changes: 17 additions & 15 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@


# 判断一个年份是否是闰年
# noinspection PyPep8Naming
def isLeapYear(year):
# 世纪年份能够被400整除为闰年
if year % 100 == 0 and year % 400 == 0:
Expand All @@ -74,10 +75,11 @@ def isLeapYear(year):


# 判断day是否是month的最后一天
def isLastDayOfMonth(month, day):
if month == 2 and isLeapYear(YEAR):
return day == leapDay
return day == monthLastDayMapping[month]
# noinspection PyPep8Naming
def isLastDayOfMonth(num_month, num_day):
if num_month == 2 and isLeapYear(YEAR):
return num_day == leapDay
return num_day == monthLastDayMapping[num_month]


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

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

res = []
langs = []
Expand All @@ -110,8 +112,7 @@ def isLastDayOfMonth(month, day):
codeLang = lang_json[langIndex]
try:
url = 'https://zh.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&uselang=zh-cn&titles=' + \
quote(codeLang[
'desc'], 'utf-8')
quote(codeLang['desc'], 'utf-8')
# 请求头部
headers = {
'User-Agent':
Expand All @@ -123,15 +124,14 @@ def isLastDayOfMonth(month, day):
# 读取响应,获得文本
wiki = json.loads(response.text)
desc = jsonpath.jsonpath(wiki, '$..extract')
codeLang['descWiki'] = desc[0].split('\n')[0]
# codeLang['descWiki'] = desc[0].split('\n')[0]
codeLang['descWiki'] = desc[0].split('。')[0] + "。"
langIndex = langIndex + 1
except Exception as e:
print("!!!!!!!error!!!!!!!!!!", e)
print("Error!", e)
continue
code_string = open('hacking-date/HackingDate.' + codeLang['code'],
'r',
encoding='utf8')
# 对内容中的特殊符合进行转义,以在HTML中显示
code_string = open('hacking-date/HackingDate.' + codeLang['code'], 'r', encoding='utf8')
# 对内容中的特殊符号进行转义,以在HTML中显示
codeLang['code'] = html.escape(code_string.read())
langs.append(codeLang)

Expand Down Expand Up @@ -213,6 +213,7 @@ def isLastDayOfMonth(month, day):
rows = rows + '</tr>'

# 生成后面的7天一页的日历
# noinspection PyUnboundLocalVariable
if weekday == 0 or len(page) == 0:
if PUNCHED:
page = pageTemplate.replace('{{pclass}}', 'page punched')
Expand All @@ -231,6 +232,7 @@ def isLastDayOfMonth(month, day):
)
page = page.replace('{{main-week}}', f'{weeks[date.getWeek()]}')
page = page.replace('{{mwclass}}', 'main-week')
# noinspection DuplicatedCode
if (str(date.getMonth()).zfill(2) + str(date.getDay()).zfill(2)
in festivals.keys()):
ldata = festivals[str(date.getMonth()).zfill(2) +
Expand Down Expand Up @@ -276,8 +278,7 @@ def isLastDayOfMonth(month, day):

page = page.replace('{{desc}}', langs[langIndex]['descWiki'])
if QR:
wiki_url = 'https://zh.wikipedia.org/wiki/' + quote(langs[langIndex][
'desc'], 'utf-8')
wiki_url = 'https://zh.wikipedia.org/wiki/' + quote(langs[langIndex]['desc'], 'utf-8')
# qr = 'https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=' + wiki_url
qr = 'https://chart.apis.google.com/chart?chs=360x360&cht=qr&choe=UTF-8&chld=M|0&chl=' + wiki_url
else:
Expand All @@ -289,6 +290,7 @@ def isLastDayOfMonth(month, day):
page = page.replace('{{wclass' + str(weekday + 1) + '}}', '')
page = page.replace(f'{{{{date{weekday + 1}}}}}', # 此处用fstring时一定要注意{要进行转义
str(date.getMonth()).zfill(2) + "-" + str(date.getDay()).zfill(2))
# noinspection DuplicatedCode
if (str(date.getMonth()).zfill(2) + str(date.getDay()).zfill(2)
in festivals.keys()):
ldata = festivals[str(date.getMonth()).zfill(2) +
Expand Down
4 changes: 2 additions & 2 deletions lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
}, {
"lang": "Swift",
"class": "swift",
"desc": "Swift_(程式語言)",
"desc": "Swift語言",
"code": "swift"
}, {
"lang": "MATLAB",
Expand Down Expand Up @@ -161,7 +161,7 @@
}, {
"lang": "Julia",
"class": "julia",
"desc": "Julia_(编程语言)",
"desc": "Julia语言",
"code": "jl"
}, {
"lang": "AppleScript",
Expand Down
3 changes: 2 additions & 1 deletion page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ <h1>{{lang}}</h1>
<span class="{{mwclass}}">{{main-week}}</span>
<span class="{{mlclass}}">{{main-ldata}}</span>
</div>
<br><br>
<pre><code class="{{class}}">{{code}}</code></pre>
<div class="{{fclass}}">
<div class="description">{{desc}}</div>
<div class="qr">
<img src="{{qr}}">
<img src="{{qr}}" alt="">
</div>
</div>
<ul class="date">
Expand Down