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设计】。

相关文章

对pandas中两种数据类型Series和DataFrame的区别详解

对pandas中两种数据类型Series和DataFrame的区别详解

1. Series相当于数组numpy.array类似 s1=pd.Series([1,2,4,6,7,2]) s2=pd.Series([4,3,1,57,8],index=['a...

python2.7安装图文教程

python2.7安装图文教程

Python安装过程,供大家参考,具体内容如下 1.下载安装程序 我们安装Python的一个重要目的是为了用IAR编译CC2640 OAD文件时执行合并文件的脚本,所以我们一起来看看Py...

Python生成词云的实现代码

Python生成词云的实现代码

1 概述 利用Python生成简单的词云,需要的工具是cython,wordcloud与anaconda. 2 准备工作 包括安装cython,wordcloud与anaconda. 2...

Python学习笔记之Break和Continue用法分析

本文实例讲述了Python学习笔记之Break和Continue用法。分享给大家供大家参考,具体如下: Python 中的Break 和 Continue break:控制何时循环...

python多线程之事件Event的使用详解

前言 小伙伴a,b,c围着吃火锅,当菜上齐了,请客的主人说:开吃!,于是小伙伴一起动筷子,这种场景如何实现 Event(事件) Event(事件):事件处理的机制:全局定义了一个内置标志...