#創建一個文件夾用來保存文件
#每x分鍾截屏一次存放到指定文件夾
import os
import pyautogui as pa
import time
def make_dir(dirs):
if not os.path.exists(dirs):
os.makedirs(dirs)
#檢測並且創建目錄
def get_file_path(dirs):
time_format = "%a %b %d %H %M %S %Y"
time_now=time.strftime(time_format,time.localtime())
file_path=os.path.join(dirs,time_now)
file_path=file_path+".png"
return file_path
#按照時間獲得截屏名稱
def screen_shot(file_path):
im1 = pa.screenshot(file_path)
#pa.screenshot方法里保存的文件不能是數字開頭,時間間隔之間也不能用:連接
def main():
while True:
time.timesleep=5
#設定間隔時長單位為秒
dirs="E:\local_dirs"
make_dir(dirs)
screen_shot(get_file_path(dirs))
main()