-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
41 lines (35 loc) · 1.74 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import httpx
import re
import urllib.parse
import datetime
def fetch_ci_time(filePath):
entries = httpx.get("https://api.github.com/repos/markyun/weekly/commits?path=" + filePath + "&page=1&per_page=1")
ciTime= entries.json()[0]["commit"]["committer"]["date"].split("T")[0]
return ciTime
# return datetime.datetime.strptime(ciTime,"%Y-%m-%d")
if __name__ == "__main__":
readmefile=open('README.md','w')
readmefile.write("# WebCIA Weekly\n\n> 本周刊内容来源于我的 RSS 信息源内容精选,包含:技术文章、产品设计、思维观点、开源项目、资源和工具、焦点资讯,为大家提供保持领先所需的见解。觉得不错可订阅 RSS,方便获取更新通知\n\n")
recentfile=open('RECENT.md','w')
for root, dirs, filenames in os.walk('./src/pages/posts'):
filenames = sorted(filenames, key=lambda x:float(re.findall("(\d+)",x)[0]), reverse=True)
for index, name in enumerate(filenames):
if name.endswith('.md'):
filepath = urllib.parse.quote(name)
oldTitle = name.split('.md')[0]
url = 'https://markyun.github.io/weekly/posts/' + oldTitle
title = '第 ' + oldTitle.split('-')[0] + ' 期 - ' + oldTitle.split('-')[1]
readmeMd= '* [{}]({})\n'.format(title, url)
dateList = ["2022-10-10","2022-09-26","2022-09-12","2022-09-05","2022-08-29"]
num = int(oldTitle.split('-')[0])
if index < 5 :
if num < 100 :
modified = dateList[99-num]
else :
modified = fetch_ci_time('/src/pages/posts/' + filepath)
recentMd= '* [{}]({}) - {}\n'.format(title, url, modified)
recentfile.write(recentMd)
readmefile.write(readmeMd)
recentfile.close()
readmefile.close()