-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGP.py
54 lines (41 loc) · 1.14 KB
/
GP.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
import urllib2,re
from BeautifulSoup import BeautifulSoup as soup
password="hello123"
ip = "http://10.5.5.9"
def GPcmd(cmd):
cmds={
"turnOn":ip+"/bacpac/PW?t="+password+"&p=%01",
"turnOff":ip+"/bacpac/PW?t="+password+"&p=%00",
"setModeImg":ip+"/camera/CM?t="+password+"&p=%01",
"getImg":ip+"/bacpac/SH?t="+password+"&p=%01"
}
urllib2.urlopen(cmds[cmd])
def GPLastImg(rename=""):
url = "http://10.5.5.9:8080/DCIM/100GOPRO/"
page = urllib2.urlopen(url).read()
html = soup(page)
jpegs = []
for href in html.findAll("a",{"class":"link"}):
x = re.search('.*href="(.+\.JPG)".*',str(href))
if x:jpegs.append(x.group(1))
lastImg = jpegs[-1]
imgUrl = url+"/"+lastImg
import PIL
from PIL import Image
import urllib2 as urllib
import io
image_file = io.BytesIO(urllib2.urlopen(imgUrl).read())
img = Image.open(image_file)
img = img.resize((400,300), PIL.Image.ANTIALIAS)
img.save(lastImg)
return lastImg
def Capture():
import time
GPcmd("setModeImg")
time.sleep(1)
GPcmd("getImg")
time.sleep(3)
img_name = GPLastImg()
return img_name
if __name__ == '__main__':
print Capture()