forked from EvanDotPro/GtkGrab
/
screenshot
executable file
·51 lines (41 loc) · 1.91 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
#!/usr/bin/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 Evan Coury (http://www.Evan.pro/)
# @copyright Copyright 2010 Pieter Kokx (http://blog.kokx.nl/)
# @package Client
import ConfigParser, sys, urllib2, os, base64, hashlib, 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')
path = '/tmp/ss.png'
os.system('scrot --b -s '+path)
os.system('convert '+path+' \( +clone -background black -shadow 60x5+10+10 \) +swap -background none -layers merge +repage '+path)
# 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();
os.remove(path)
os.system('echo -n "' + url + '" | xclip -selection c')
os.system('notify-send --hint=int:transient:1 "Screenshot Uploaded" "Copied URL to clipboard: ' + "\n" + url + '"')