-
Notifications
You must be signed in to change notification settings - Fork 12
/
screenshot
executable file
·70 lines (59 loc) · 2.54 KB
/
screenshot
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
#!/usr/bin/env python
# This file is part of GtkGrab.
#
# GtkGrab is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# GtkGrab is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GtkGrab. If not, see <http://www.gnu.org/licenses/>.
#
# @category GtkGrab
# @license http://www.gnu.org/licenses/gpl-3.0.txt GPL
# @copyright Copyright 2010-2013 Evan Coury (http://www.Evan.pro/)
# @copyright Copyright 2010-2013 Pieter Kokx (http://kokx.nl/)
# @package Client
import ConfigParser, sys, urllib2, os, base64, hashlib, pyperclip, time
config = ConfigParser.ConfigParser()
config.readfp(open(os.path.dirname(sys.argv[0]) + '/config.cfg'))
user = config.get('GtkGrab','username')
token = config.get('GtkGrab','password')
postURL = config.get('GtkGrab','posturl')
command = config.get('GtkGrab','command')
if len(sys.argv) > 1 and sys.argv[1] == 'gif':
command = os.path.dirname(__file__) + '/' + config.get('GtkGrab','gifCommand')
notifyCommand = config.get('GtkGrab','notifyCommand')
path = config.get('GtkGrab','capPath')
os.system(command.replace("%s", path))
if postURL == 's3':
bucket = config.get('GtkGrab', 's3bucket')
prefix = config.get('GtkGrab', 's3prefix')
filename = hashlib.sha1()
filename.update(str(time.time()))
filename = filename.hexdigest()
s3Url = "s3://" + bucket + "/" + prefix + "/" + filename + ".png"
uploadCommand = "s3cmd ";
if (os.path.exists('.s3cfg')):
uploadCommand += "-c .s3cfg "
uploadCommand += "put " + path + " " + s3Url + " --acl-public"
os.system(uploadCommand)
url = "http://"+bucket+".s3.amazonaws.com/caps/"+filename+".png"
else:
# encode the screenshot with base64
data = base64.b64encode(open(path, 'r').read())
# hash the data with the user's secret token and send that as header
hash = hashlib.sha1()
hash.update(data)
hash.update(token)
headers = {'X-Username': user, 'X-Signature': hash.hexdigest(), 'Content-Type': 'text/xml'}
# upload the url and give the screenshot url to the user
url = urllib2.urlopen(urllib2.Request(postURL, data, headers)).read()
# remove the file
os.remove(path)
pyperclip.copy(url)
os.system(notifyCommand.replace('%s', url))