把基于Python自动脚本转成了批处理

在上一个帖子里,已经实现了本地文件同步更新到站点。是通过Python运行了一个.py文件的形式,本来丢在VPS也不用管,但因本身VPS也运行我其他程序,导致手机远程登录的时候,查看那个py程序不方便(屏幕小)

于是,在Python文件格式的基础上,混编成了批处理文件,这样,各司其职,更好些。 可以把这个bat文件放在任意文件夹了。

代码:

"""
::==============this is the note
::batch and Python hybrid coding
::Van

::Below is code
@echo off&cls
echo batch echo
python.exe %0&pause
::=====================comments
"""
#below is your Python code

__author__ = 'Van'


import os
import time
import subprocess

file = 'C:\\Users\\Administrator\\TestBlog\\vansnowpea.github.io\\source\\_posts\\'

path = "C:\\Users\\Administrator\\TestBlog\\vansnowpea.github.io"

t1 = os.path.getmtime(file)

print (t1)

def update_Hexo():
    print ('hi')
    p = subprocess.Popen('cmd.exe', shell=True, stdin=subprocess.PIPE)
    p.stdin.write('cd '+ path + '\n')
    p.stdin.write('hexo generate --deploy' + '\n')
    p.stdin.close()


while 1:
    time.sleep(1)
    t2 = os.path.getmtime(file)
    if t2 == t1:
        pass

    else:
        print('file was modified, will update Hexo!')
        update_Hexo()
        print(' update Hexo done!')
    t1 = t2



if __name__ == "__main__":
pass