手拉手定制GitHub个人首页
白日不到处,青春恰自来。
苔花如米小,也学牡丹开。
前情提要
GitHub
最近被收购之后变得异常活跃各种优化不断
- 基于
python
爬些自己想要的数据- 拥有自己的
Action
开启定时任务- 以自己命名的特殊库会展示到个人首页
xkloveme/xkloveme is a special repository. ItsREADME.md
will appear on your public profile!
实施
方案清晰后可以,着手开发
md
文件支持图片和svg
,首页每日自动替换bing
图片
新建GitHub
同名库
当新建一个同名库的时候
README.md
文件内容会展示到个人首页
使用徽章
- shields.io/的徽章
GitHub
徽标的官方网站是 shields.io/,我萌可以在官网预览绝大部分的徽标样式,然后选择自己喜欢的(当然首先需要适用于自己的目标项目)徽标,添加到自己的项目文档中去 - forthebadge.com/的徽章
- 项目的徽章
每日图片爬虫
人生苦短我用python
基于python3,爬
https://cn.bing.com/的背景图
- 导入对应的库
import bs4
import tools
from bs4 import BeautifulSoup
- 爬背景图获取
URL
def getSource(self):
img = ''
url = 'https://cn.bing.com'
req = [
'user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Mobile Safari/537.36',
]
res = self.T.getPage(url, req)
if res['code'] == 200:
soup = BeautifulSoup(res['body'], 'html.parser')
img = url + soup.find(id='sh_url').get('value')
return img
- 生成
md
文件
if __name__ == '__main__':
obj = Source()
img = '[![每日壁纸](' + obj.getSource() + ')](https://www.jixiaokang.com)'
readme = root / "README.md"
readme_contents = open(readme, 'w')
md = "\n".join(
[
'[![xkloveme](https://raw.githubusercontent.com/xkloveme/xkloveme/master/logo.svg)](https://www.jixiaokang.com)',
'[![forthebadge](https://forthebadge.com/images/badges/ages-20-30.svg)](https://www.jixiaokang.com) '
'[![forthebadge](https://forthebadge.com/images/badges/for-you.svg)](https://www.jixiaokang.com) '
'[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://www.jixiaokang.com)',
'[![xkloveme](https://raw.githubusercontent.com/xkloveme/xkloveme/master/slogan.svg)](https://www.jixiaokang.com)',
"# 每日壁纸",
img,
'# 推荐链接🔗',
'> [项目说明](https://github.com/xkloveme/xkloveme/blob/master/PROJECT.md)如果想展示您的主页🔗请`pr`,如有喜欢请关注\n',
]
)
link = root / "LINK.md"
link_contents = open(link, 'r')
link_list = link_contents.readlines()
readme_contents.write(md)
readme_contents.writelines(link_list)
readme_contents.close()
- 配置
CI
,这里选用官方Action
,速度快稳定性高,配置简单
- 在项目新建
Token
SIMONW_TOKEN: ${{ secrets.SIMONW_TOKEN }} // 为了自动推送到库
- 最重要的三个
job
- name: Install Python dependencies
run: |
python -m pip install -r requirements.txt
- name: Update README
env:
SIMONW_TOKEN: ${{ secrets.SIMONW_TOKEN }}
run: |-
python main.py
cat README.md
- name: Commit and push if changed
run: |-
git diff
git config --global user.email "readme-bot@example.com"
git config --global user.name "README-bot"
git add -A
git commit -m "AUTO:👷♀️Updated content" || exit 0
git push
- 开启定时
每小时32分会自动运行
schedule:
- cron: '32 * * * *'
大功告成
参与进来
如果您也喜欢折腾的话,我在这里发起一个项目,以便展示您个人主页.
希望您可以fork
此项目
git clone https://github.com/xkloveme/xkloveme.git --depth 1
定制您个人想要的主页
pr
到LINK.md
,格式如下:
- [xkloveme 的主页](https://github.com/xkloveme)