用python控制同步hexo脚本

本文介绍了一个使用Python编写的脚本,该脚本能够自动完成Hexo博客的同步工作,通过更改目录并执行一系列命令来简化博客的发布流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

之前一直在windows下面写hexo博客,但是每次同步需要运行一大堆指令,于是想到用python 写一个脚本来自动同步,用到了os.chdir,因为直接os.system('cd xxx')会自动返回当前路径。

具体程序如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017/8/10 19:42

import os
os.chdir((ur'E:\项目\blog'))
os.system('hexo d \-g')
os.system(ur'git add .')
os.system("git commit -m 'Updated'")
os.system('git push origin source')
print 'done'

然后将启动这个命令设置为简短的命令,类似于alias

Run the below command in a command prompt to alias ls to run the command dir. The $* on the end are required so that any additional arguments are also passed to the dir command.

1 doskey ls=dir $*

The problem with this is that all of your alias commands will be lost when you close the cmd session. To make them persist we need to create a batch file and add the entry to the windows registry.

Create a new folder in the windows directory called bin and create a new batch file inside it.

12 C:>mkdir c:\windows\binC:>notepad.exe c:\windows\bin\doskey.bat

Add your entries to the batch file in the below format.

12345 @echo offdoskey ls=dir doskey cp=copy $doskey cat=type $*

Next, open up regedit.exe and add an entry to the batch file to make the doskey commands permanent for each cmd session.

1 HKEY_CURRENT_USER\Software\Microsoft\Command Processor

Add a new String Value called AutoRun and set the absolute path in the value of c:\windows\bin\doskey.bat.

The doskey.bat file will now be executed before opening a new cmd session which will set all of your alias ready for you to use.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值