大リモート時代
リモート会議,リモート授業,リモート面接...
コロナウイルスの影響で良くも悪くも,様々なことがインターネットを介して行われるようになりました.私のような怠惰な人間は授業や会議中につい寝てしまうことがあるわけです.大抵の場合,資料はメール等で配布されるのですが,愛のある(意地悪な)先生となると話は変わってきます.レジュメ配布無し・録音録画禁止といった方針の授業において,居眠りは落単そのものでしょう.Zoomなんかで録画しようものなら即バレからのご指導間違いなしですね.ほとんどの生徒はスクリーンショットをスライドごとに行うのですが,それすら面倒くさい...
こんな状況を解決する,定期画面キャプチャをpythonで書いてみました.怠惰な方はお試しあれ.
Capturing.py
外部ライブラリはPILだけですね.
from PIL import ImageGrab
import time
import os
from os.path import expanduser
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.filedialog
def capture(event):
span = int(entry_span.get())
split = int(entry_split.get())
lap_imagine = span/split
global captures
captures = []
for i in range(split):
start = time.time()
captures.append(ImageGrab.grab())
lap_real = time.time() - start
if lap_imagine > lap_real:
time.sleep(lap_imagine - lap_real)
else:
print("split:{} is too many\n1cycle:{}sec".format(split, lap_real))
def save(event):
iDir = os.path.abspath(os.path.dirname(__file__))
iDirPath = tkinter.filedialog.askdirectory(initialdir=iDir)
dir = iDirPath + "/{}".format(entry_dir.get())
try:
os.chdir(dir)
except FileNotFoundError:
os.mkdir(dir)
os.chdir(dir)
for i, c in enumerate(captures):
c.save("scene{}.png".format(i))
if __name__ == '__main__':
caputures = []
root = tk.Tk()
root.title("Caputo")
root.geometry("200x322")
button_cap = tk.Button(root, text="Capture Scene")
button_cap.pack(fill=tk.BOTH, expand=1)
button_cap.bind('<1>', capture)
entry_span = tk.Entry(root)
entry_span.pack(fill=tk.BOTH, expand=1)
entry_span.insert(0, "Capturing Second")
entry_split = tk.Entry(root)
entry_split.pack(fill=tk.BOTH, expand=1)
entry_split.insert(0, "Capturing Leaves")
button_save = tk.Button(root, text="Save Captures")
button_save.pack(fill=tk.BOTH, expand=1)
button_save.bind('<1>', save)
entry_dir = tk.Entry(root)
entry_dir.pack(fill=tk.BOTH, expand=1)
entry_dir.insert(0, "Saving Folder Name")
root.mainloop()
実行画面
- Capture Scene:画面キャプチャ開始
- Capturing Second:キャプチャ時間(特に制限なし)
- Capturing Leaves:キャプチャ枚数
- Save Captures:キャプチャ保存
- Saving Folder Name:保存フォルダ名
実行結果
キャプチャ内容は伏せてますが下図のようになります.
キャプチャした内容の取扱いは慎重に!自己責任で!