forked from ZKeeer/WeChatAssistant
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscreenshoot.py
46 lines (36 loc) · 1.24 KB
/
screenshoot.py
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
import os
import platform
from time import time
import itchat
def GetImagePath():
if not os.path.exists("./ScreenShoot/"):
os.mkdir("./ScreenShoot/")
return "./ScreenShoot/"
def SC():
im_path = GetImagePath()
im_name = "{}{}.{}".format(im_path, int(time()), "png")
im = None
if platform.system() == 'Windows' or platform.system() == 'Darwin':
try:
from PIL import ImageGrab
im = ImageGrab.grab()
except OSError as e:
itchat.send("截图失败,请重试。", toUserName="filehelper")
return
elif platform.system() == 'Linux':
try:
import pyscreenshot as ImageGrab
im = ImageGrab.grab()
except OSError as e:
itchat.send("截图失败,请重试。", toUserName="filehelper")
return
im.save(im_name)
if os.path.exists(im_name):
try:
itchat.send("@img@{}".format(im_name), toUserName="filehelper")
except BaseException as e:
import traceback
traceback.print_exc()
itchat.send("发送截图失败,请重试。", toUserName="filehelper")
else:
itchat.send("截图失败,请重试。", toUserName="filehelper")