Git+Crontab实现博客自动发布

2018-07-13

Git 免密码上传

1、在/home/username/ 目录下新建文本文件,用touch命令 touch .git-credentials

2、然后在这个文件中输入以下内容: https:{username}:{password}@github.com 

{username}和_{password}_是用户名和密码,比如我的就是:https:lijialin:123456@github.com 

3、修改git配置,执行命令:

git config --global crediential.helper store

这个命令会在.gitconfig文件中添加配置username和password: 4、生成上传的公钥,并且添加到github主页,setting中的SSH key中。 之后就可以实现免密码登录

设置完git免用户名和密码后,我们修改python代码如下:

uploadcrontab.py

  # -*-encoding:utf8-*-
  #!/usr/bin/env python
   import os
   import subprocess
   import datetime
   filepath = os.path.dirname(__file__)
   os.chdir(filepath)
   subprocess.call(["git", "add", "."])
   subprocess.call(["git", "commit", "-m", "auto push at " + str(datetime.datetime.now())]) # 加上当前系统的时间
 subprocess.call(["git", "push"])

os.chdir(filepath)用于切换的当前目录,相当于cd

定时任务

```crontab -e`` 定时任务的格式如下: minute hour day month week command 1

  1. https://blog.csdn.net/u010429424/article/details/76896918 

点击查看评论

所有文章