惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Application and Cybersecurity Blog
Application and Cybersecurity Blog
A
About on SuperTechFans
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Help Net Security
Help Net Security
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
O
OpenAI News
美团技术团队
月光博客
月光博客
Apple Machine Learning Research
Apple Machine Learning Research
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
Cyberwarzone
Cyberwarzone
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google Online Security Blog
Google Online Security Blog
T
Tenable Blog
S
Security Affairs
博客园_首页
S
Schneier on Security
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
Spread Privacy
Spread Privacy
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
K
Kaspersky official blog
Hugging Face - Blog
Hugging Face - Blog
TaoSecurity Blog
TaoSecurity Blog
博客园 - 聂微东
Vercel News
Vercel News
M
MIT News - Artificial intelligence
T
Troy Hunt's Blog
B
Blog
MongoDB | Blog
MongoDB | Blog
Martin Fowler
Martin Fowler
Attack and Defense Labs
Attack and Defense Labs
L
LINUX DO - 最新话题
D
DataBreaches.Net
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - Franky
W
WeLiveSecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
F
Fortinet All Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Check Point Blog
H
Hacker News: Front Page

夜行人

回家路上 第一期的直播演示项目 震动检测器 正能量 在线参观CodeLab Neverland 发布 CodeLab Adapter 3.3.1 DynamicTable 之 纸糊方向盘 CodeLab DynamicTable: 一个可实施的技术方案 CodeLab Insight 发布 Alpha 版 情人节 Home Assistant 周报 && IoT 周报 (02) Joplin: 关注隐私的 Evernote 开源替代软件 浏览器的未来与 Web 传感器 Home Assistant 周报 && IoT 周报 (01) 百宝箱(01) 论自由 介绍 WebThings Home Assistant 周报 && iot 周报 (00) 百宝箱(00) 毛姆读书心得 传世之作 周末徒步 CodeLab Adapter ❤️ Jupyter/Python 航班 躲雨 夏令营途中 [译]思想--作为一种技术 The future of coding 美国之行 三门问题的程序模拟 从Python转向Pharo https://blog.just4fun.site/post/iot/iot-open-source-projects/ Python异步编程笔记 https://blog.just4fun.site/post/iot/iot-open-source-hardware-community/ 万物积木化开发者社区 CodeLab ❤️ Blender Scratch3技术分析之云变量 API(第7篇) [译]对管道(Pipes)的偏爱 [译]提出正确的问题比得到正确答案更重要 蓝牙设备与Scratch3.0 创建你的第一个Scratch3.0 Extension Scratch3技术分析之项目内部数据(第6篇) Scratch3技术分析之社区 API(第5篇) Scratch3技术分析之User API(第4篇) Scratch3技术分析之项目主页API(第3篇) Scratch3技术分析之静态资源API(第2篇) Scratch3.0、micro:bit与Windows7 https://blog.just4fun.site/post/iot/zerynth-vs-micropython/ 核聚变、方所与半宅空间 可视化编程为何是个糟糕的主意 codelab.club周末聚会 关于codelab.club '下一件大事'是一个房间 Hungry Robot - Eat everything 编程作为一种思考方式 今日简史 史蒂夫·乔布斯传 罗素自选文集 https://blog.just4fun.site/post/edx/tianjin-scratch-ai/ https://blog.just4fun.site/post/edx/richie-cms-openedx/ 徒步武功山 WebUSB与micro:bit 积木化编程与3D场景 夜宿武功山顶 scratch3-adapter接入优必选Alpha系列机器人 https://blog.just4fun.site/post/edx/video-migration-note/ scratch3-adapter重构笔记 https://blog.just4fun.site/post/edx/edx-community-members/ 两种硬件编程风格的比较 使用micro:bit自制PPT翻页笔 柏拉图对话集 scratch3.0 + micro:bit 七月电影放映计划 非营利组织的管理 Screenly--用树莓派让任何屏幕变为可编程的数字标牌 以最佳实践开始你的Django项目 micro:bit与事件驱动 为Scratch3.0设计的插件系统(上篇) OCR应用一例 近两年读过的一些好书 blockly开发之使用python驱动浏览器中的turtle(2) 牛顿新传 文学理论入门 逻辑的引擎 人生的意义 blockly开发之生成并运行js代码(1) blockly开发之hello world(0) micro:bit使用笔记 神器之Termux https://blog.just4fun.site/post/iot/micropython-notes/ Cozmo what is this Scratch的前世今生 下段旅程 我行在远方 爆裂 途中杂记 https://blog.just4fun.site/post/edx/open-edx-startup/ cozmo系列之入门 - 有性格且可编程的机器人 PaperWeekly开发笔记 创业二三事
for dinner
2015-08-16 · via 夜行人

部门新来了个同事,负责视频编导和制作。经常需要使用Premiere渲染视频,这是一项十分费时的工作,动辄3-4个小时。

同事时常在傍晚4-5点开始渲染视频,待其完成,将渲染好的视频发送出去,再关闭电脑回家。这样一来,往往就到晚上9/10点了。

这样一来,就没空做晚饭和次日的便当了,念其厨艺棒极,为了午饭时间能闻到土豆炖牛肉的香味,我决定写个脚本完成这个工作。


#思路 ###任务描述 写一个python脚本,该脚本运行在Windows环境下,该脚本监控视频导出目录,发现视频文件生成时,将其同步到云盘,同步完成后给相关人员发送邮件,通知其下载。此后关机。

###任务分解

  • 在Windows搭建python环境(easy)
  • 使用watchdog监控视频导出目录变化
  • 使用bypy同步文件到百度网盘
  • 使用smtp发送邮件
  • 关机:from sys import system;system('halt')

#准备工作

###配置bypy 在终端执行bypy.py info,之后按照提示操作就行

#show my code ###源代码 看这里:for_dinner

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#for_dinner.py
#!/usr/bin/env python
# encoding: utf-8

import sys
import time
import logging
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler,FileSystemEventHandler

from send_emails import send_mail
import commands
from os import system
from config import watchdir,watch_file_type,remotedir

def notice2download(sub=u"下载视频",content=u"请登录百度网盘"):
    send_mail(sub,content)

def upload_watch_file(file):
    pass

class MyHandler(FileSystemEventHandler):
    def on_created(self, event):
        if (event.src_path).endswith(watch_file_type):
            print event.src_path
            #上传到云盘
            mycommands = "bypy.py upload " + event.src_path + " " + remotedir
            output = commands.getoutput(mycommands)
            print output
            #发送邮件
            content = u"新建文件:"+event.src_path
            notice2download(content=content)
            time.sleep(60*10) #十分钟后关机
            system('halt')

    def on_modified(self, event):
        if (event.src_path).endswith(watch_file_type):     #监控指定文件内容、权限等变化
            print "log file %s changed!" % event.src_path

if __name__ == "__main__":
    path = sys.argv[1] if len(sys.argv) > 1 else watchdir
    event_handler = MyHandler()
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()          
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#send_emails.py
#!/usr/bin/env python
# encoding: utf-8

import smtplib
from email.mime.text import MIMEText
from config import mailto_list,mail_host,mail_user,mail_pass



def send_mail(sub,content,to_list=mailto_list):
    msg = MIMEText(content, 'html', 'utf-8')
    msg['Subject'] = sub
    msg['From'] = mail_user
    try:
        server = smtplib.SMTP()
        server.connect(mail_host)
        server.login(mail_user,mail_pass)
        server.sendmail(mail_user, to_list, msg.as_string())
        server.close()
        return True
    except Exception, e:
        print str(e)
        return False

配置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#config.py
#!/usr/bin/env python
# encoding: utf-8

watchdir = "/tmp" #监控的目录
watch_file_type = "txt" #监控的文件类型
remotedir = "remotedir" #云盘上的目录,需要先创建bypy.py mkdir remotedir
mailto_list=["someone@example.com",] #接收人
mail_host="smtp.example.com"  #设置服务器
mail_user="user@example.com"    #用户名
mail_pass="password"   #口令

#使用 ###mac/linux sudo python for_dinner.py

其中/tmp是需要监控的目录

关机权限需要sudo

###windows 写一个bat脚本

1
2
#run.bat
python for_dinner.py

右键以管理员身份运行

文章作者 种瓜

上次更新 2015-08-16