python实现截取屏幕保存文件,删除N天前截图的例子

yipeiwu_com6年前Python基础

我就废话不多说,直接上代码吧!

from PIL import ImageGrab
import time
import schedule
import os
import shutil
import datetime

days = -3
# 截屏
def savepic():
 im = ImageGrab.grab()
 now = time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime())
 day = time.strftime("%Y%m%d", time.localtime())
 file_path_top = 'c:\\tmp\\'
 if not os.path.exists(file_path_top):
  os.mkdir(file_path_top)
 file_path = 'c:\\tmp\\'+day+'\\'
 if not os.path.exists(file_path):
  os.mkdir(file_path)
 im.save(file_path+now+'.jpg')

# 删除文件
def deletefile(): 
 today = datetime.datetime.now()
 offset = datetime.timedelta(days=days)
 re_date = today + offset
 file_dir = r'C:\tmp'
 for root, dirs, files in os.walk(file_dir):
  for i in dirs:
   if(i<=re_date.strftime('%Y%m%d')):
    path = 'C:\\tmp\\'+i
    if (os.path.exists(path)):
     shutil.rmtree(path)
         
schedule.every(60).seconds.do(savepic)
schedule.every().day.at("00:30").do(deletefile)
while True:
  schedule.run_pending()
  time.sleep(1)

以上这篇python实现截取屏幕保存文件,删除N天前截图的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

numpy:np.newaxis 实现将行向量转换成列向量

np.newaxis 新增一个轴 如何将数组[0,1,2]转换成列向量 用ndarray[: , np.newaxis] 代码实质就是将原本的(0,1,2)移到行上,然后新增一列 其实...

windows环境中利用celery实现简单任务队列过程解析

windows环境中利用celery实现简单任务队列过程解析

这篇文章主要介绍了windows环境中利用celery实现简单任务队列过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 一、背景...

开始着手第一个Django项目

一但你安装好了python,django和(可选的)数据库及相关库,你就可以通过创建一个project,迈出开发django应用的第一步。 项目 是 Django 实例的一系列设置的集合...

pytorch实现特殊的Module--Sqeuential三种写法

我就废话不多说了,直接上代码吧! # -*- coding: utf-8 -*- #@Time :2019/7/1 13:34 #@Author :XiaoMa import...

使用PyInstaller将Pygame库编写的小游戏程序打包为exe文件及出现问题解决方法

使用PyInstaller将Pygame库编写的小游戏程序打包为exe文件及出现问题解决方法

下面看下通过Pyinstaller打包Pygame库写的小游戏程序出现的问题解决方法 # -基于Python的Pygame库的GUI游戏 游戏内容是通过飞船发射子弹来射击外星人 空格键为...