-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.py
63 lines (54 loc) · 1.55 KB
/
init.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
#!/usr/bin/python
import logging
from ghost import Ghost
from urlparse import urlparse
from tempfile import mkstemp
CLIENT_ID = "a7c30de4f98751b"
x1=0
y1=0
x2=1280
y2=1280
timeout=None
def ghostCapture(screen_url,web_timeout=20):
import time
gh = Ghost(display=":99",wait_timeout=int(web_timeout),
viewport_size=(x2,y2), ignore_ssl_errors=True,
log_level=logging.FATAL)
ghost_page,resources= gh.open(screen_url,
auth=('none', 'none'))
img_path=mkstemp(suffix=".png")[1]
gh.set_viewport_size(x2,y2)
time.sleep(timeout)
gh.capture_to(img_path,region=(x1,y1,x2,y2))
return img_path
def usage(prog):
print("usage: visit-page uri [timeout]")
if __name__ == "__main__":
import sys,os
url=None
host=None
try:
url = sys.argv[1]
if not url.startswith("http"):
url="http://"+url
host=urlparse(url).netloc
except Exception,e:
usage(sys.argv[0])
sys.exit(1)
try:
timeout=int(sys.argv[2])
if not( 0 < timeout < 60):
sys.stdout.write("timeout must be between 0 and 60 seconds\n")
usage(sys.argv[0])
sys.exit(1)
sys.stdout.write("Timeout set to %d seconds\n"%timeout)
except:
timeout=0
sys.stdout.write("Capturing '%s'\n"%url)
sys.stdout.flush()
image_path=ghostCapture(url)
import pyimgur
im = pyimgur.Imgur(CLIENT_ID)
uploaded = im.upload_image(image_path,title=host)
os.remove(image_path)
print(uploaded.link)