-
Notifications
You must be signed in to change notification settings - Fork 1
/
gopro.py
62 lines (44 loc) · 1.59 KB
/
gopro.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
import requests
import re
import wget
import time
goproHTTPRoot = "http://10.5.5.9/videos/DCIM/"
goproHTTPShutter = "http://10.5.5.9/gp/gpControl/command/shutter?p=1"
def takeshot():
r = requests.get(goproHTTPShutter)
return r.status_code
def getFoldersList():
r = requests.get(goproHTTPRoot)
folderList = re.findall(r'href=".*/"', r.text)
folderListResult = []
for i in range(len(folderList)):
folderName = folderList[i].replace("href=\"", "").replace("\"", "")
folderListResult.append(folderName)
return folderListResult
def getPhotosNameList(folder):
r = requests.get(goproHTTPRoot + folder)
photoNameList = re.findall(r'href=".*.JPG"', r.text)
photoNameListResult = []
for i in range(len(photoNameList)):
photoName = photoNameList[i].replace("href=\"", "").replace("\"", "")
photoNameListResult.append(folder + photoName)
return photoNameListResult
def getAllPhotoPaths():
folders = getFoldersList()
result = []
for i in range(len(folders)):
photosNames = getPhotosNameList(folders[i])
for j in range(len(photosNames)):
result.append(photosNames[j])
return result
def getLastPhotoPath():
allPhotosPathsList = sorted(getAllPhotoPaths())
return allPhotosPathsList[-1]
def downloadPhoto(url):
filename = wget.download(url)
return filename
def takePhotoAndDownload():
status = takeshot()
time.sleep(5)
lastPhoto = getLastPhotoPath()
return downloadPhoto(goproHTTPRoot + lastPhoto)