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

相关文章

python将ip地址转换成整数的方法

本文实例讲述了python将ip地址转换成整数的方法。分享给大家供大家参考。具体分析如下: 有时候我们用数据库存储ip地址时可以将ip地址转换成整数存储,整数占用空间小,索引也会比较方便...

Python中一些自然语言工具的使用的入门教程

NLTK 是使用 Python 教学以及实践计算语言学的极好工具。此外,计算语言学与人工 智能、语言/专门语言识别、翻译以及语法检查等领域关系密切。 NLTK 包括什么 NLTK 会被自...

新年快乐! python实现绚烂的烟花绽放效果

新年快乐! python实现绚烂的烟花绽放效果

做了一个Python的小项目。利用了一点python的可视化技巧,做出烟花绽放的效果,文章的灵感来自网络上一位大神。 一.编译环境 Pycharm 二.模块 1.tkinter:这个...

在django admin中添加自定义视图的例子

django admin提供了完善的用户管理和数据模型管理,方便实用。研究了一下在admin里面添加自己的页面。 在admin.py里继承django.contrib.admin.Mod...

python实现用户登录系统

本文实例为大家分享了用户登录系统python实现代码,供大家参考,具体内容如下 注意事项: 1、使用python3执行程序。按提示输入1或2,登录或退出程序 2、输入用户名后,如果用...