-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAutoShotThread.py
71 lines (65 loc) · 2.56 KB
/
AutoShotThread.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
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
#coding: utf-8
import threading
import shutil
import os
import time
class AutoShotThread(threading.Thread):
def __init__(self,shotpath,filename,shotTimeInterval,shotNum):
threading.Thread.__init__(self)
self.shotpath = shotpath
self.shotNum = shotNum
self.shotTimeInterval = shotTimeInterval
print self.shotpath
self.filename = filename
self.sourcefile = 'D:\\screenshot\\monkeyPic.png'
def run(self):
self.state = 0
temp = 0
while(self.state == 0):
print 'run'
temp = temp + 1
time.sleep(0.01)
try:
self.file = self.file = open('D:\\screenshot\\ctrl.txt','r')
self.state = int(self.file.read())
self.file.close()
except:
print 'ctrl file is empty'
if temp > 10:
print 'hahahaha'
self.state = 1
print '------' + str(self.state)
self.targetfile = self.shotpath + self.filename
num = 0
while(num < self.shotNum):
num = num + 1
self.copyfile()
time.sleep(self.shotTimeInterval * 60)
print 'auto shot finish'
def copyfile(self):
print 'copy'
if os.path.exists(self.shotpath):
if os.path.exists(self.targetfile):
print 'file exit'
temp = 0
self.targetfile = self.shotpath + self.filename[:len(self.filename) - 4] + str(temp) + '.png'
print self.targetfile
while(os.path.exists(self.targetfile)):
temp = temp + 1
self.targetfile = self.shotpath + self.filename[:len(self.filename) - 4] + str(temp) + '.png'
print self.targetfile
shutil.copy(self.sourcefile,self.targetfile)
else:
print 'file not exit'
shutil.copy(self.sourcefile,self.targetfile)
else:
os.makedirs(self.shotpath)
if os.path.exists(self.targetfile):
temp = 0
self.targetfile = self.shotpath + self.filename[:len(self.filename) - 4] + str(temp) + '.png'
while(os.path.exists(self.targetfile)):
temp = temp + 1
self.targetfile = self.shotpath + self.filename[:len(self.filename) - 4] + str(temp) + '.png'
shutil.copy(self.sourcefile,self.targetfile)
else:
shutil.copy(self.sourcefile,self.targetfile)