-
Notifications
You must be signed in to change notification settings - Fork 0
/
capture_img.py
60 lines (51 loc) · 1.96 KB
/
capture_img.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
from time import sleep
from datetime import datetime
import gphoto2 as gp
import signal, os, subprocess
#kill processgphoto2
def killgphoto2Process():
#p = subprocess.Popen(['ps', '-A'], (stdout = subprocess.PIPE)
#out, err= p.communicate()
# line in out.splitlines():
# if b'gvfsd-gphoto2' in line:
# pid = int(line.split(None,1) [0])
# os,kill (pid, signal.SIGKILL)
gp(["--summary"]) #output summary
gp(["--show-preview"])
sleep(10) #view the image
picID= "Image"
clearCom = ["--folder", "location of memorycard", "-R", "--delete-all-files"]
triggerCom = ["--Trigger-capture"]
downloadCom = ["--get-all-files"]
folder = shot_date + picID
save_loc = "location of save" + folder
def createFolder(): #make folder to store
try:
os.makedirs(save_loc)
except:
print("Already have one")
os.chdir(save_loc)
def capture():
gp(triggerCom)
sleep(5)
gp(downloadCom)
gp(clearCom)
def renamefiles(ID):
shot_date = datetime.now().strftime("%Y-%m-%d")
shot_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
for filename in os.listdir("."):
if len(filename) < 13:
if filename.endswith(".JPG"):
os.rename(filename, (shot_time + ID + ".JPG"))
print("Renamed the JPG!")
elif filename.endswith(".RAW"):
os.rename(filename, (shot_time + ID + ".RAW"))
print("Renamed the RAW!")
##Main function happens here
killgphoto2Process()
gp(clearCom)
while True:
createFolder()
capture()
renamefiles(picID)
sleep(10)