Repository navigation
Expand file tree
/
Copy pathauto_prtsc.py
More file actions
72 lines (59 loc) · 1.85 KB
/
Copy pathauto_prtsc.py
File metadata and controls
72 lines (59 loc) · 1.85 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import time
import os
import datetime
import pyautogui
import img2pdf
from PIL import Image
#########################
# 変数定義
# (環境に応じて変更する)
#########################
# ページ数
total_pages = 5
# 取得範囲:左上座標
x1, y1 = 0, 0
# 取得範囲:右下座様
x2, y2 = 960, 540
# 開始準備時間(秒)
prep_time = 5
# スクショ間隔(秒)
interval = 1
# 出力フォルダ頭文字
dir_prefix = "output"
# 出力ファイル頭文字
file_prefix = "picture"
#########################
# 処理開始
#########################
# 待機時間
# (この間にスクショを取得するウィンドウをアクティブにする)
print(f'Please activate your target window in {prep_time} seconds!')
time.sleep(prep_time)
print('start!')
# 出力フォルダ作成(フォルダ名:頭文字_年月日時分秒)
img_ext = ".png"
out_dir = dir_prefix + "_" + str(
datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
os.mkdir(out_dir)
# ページ数分スクリーンショットをとる
for p in range(total_pages):
page = str(p + 1).zfill(4)
print(f'page {page}')
# 出力ファイル名(頭文字_連番.png)
out_filename = file_prefix + "_" + page + img_ext
# スクリーンショット取得・保存
s = pyautogui.screenshot(region=(x1, y1, x2 - x1, y2 - y1))
s.save(out_dir + '/' + out_filename)
# 右矢印キー押下
pyautogui.keyDown('right')
pyautogui.keyUp('right')
# 次のスクリーンショットまで待機
time.sleep(interval)
# PDFに変換
pdf_fiename = out_dir + '/' + file_prefix + '.pdf'
with open(pdf_fiename, "wb") as f:
f.write(
img2pdf.convert([
Image.open(out_dir + '/' + j).filename for j in os.listdir(out_dir)
if j.endswith(img_ext)
]))