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

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

相关文章

在Python中使用Neo4j的方法

在Python中使用Neo4j的方法

Neo4j是面向对象基于Java的 ,被设计为一个建立在Java之上、可以直接嵌入应用的数据存储。此后,其他语言和平台的支持被引入,Neo4j社区获得持续增长,获得了越来越多的技术支持者...

python将txt等文件中的数据读为numpy数组的方法

实际中,很多数据都是存为txt文件、csv文件等,但是在程序中处理的时候numpy数组或列表是最方便的。本文简单介绍读入txt文件以及将之转化为numpy数组或列表的方法。 1 将txt...

python读取word 中指定位置的表格及表格数据

python读取word 中指定位置的表格及表格数据

1.Word文档如下: 2.代码 # -*- coding: UTF-8 -*- from docx import Document def readSpecTable(filen...

Python中用字符串调用函数或方法示例代码

前言 本文主要给大家介绍了关于Python用字符串调用函数或方法的相关内容,分享出来供大家参考学习,下面来一起看看详细的介绍: 先看一个例子: >>> def fo...

python实现dict版图遍历示例

复制代码 代码如下:#_*_coding:utf_8_import sysimport os class Graph():    def __init__(...