Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/zerd/lookit into zerd-master
Browse files Browse the repository at this point in the history
  • Loading branch information
zachtib committed Apr 10, 2011
2 parents 93e4a40 + 1374b99 commit c5d47d7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
37 changes: 29 additions & 8 deletions src/lookit
Expand Up @@ -29,6 +29,7 @@ import tempfile
import time
import urllib
import urlparse
import shutil

from optparse import OptionParser

Expand All @@ -51,6 +52,8 @@ except ImportError:

CONF_FILE = os.path.expanduser('~/.config/lookit.conf')
TRASH_DIR = os.path.expanduser('~/.local/share/Trash/files')
XDG_CACHE_HOME = os.environ.get('XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
LOG_FILE = os.path.join(XDG_CACHE_HOME, 'lookit.log')

class LookitApp:

Expand Down Expand Up @@ -143,9 +146,9 @@ class LookitApp:

def process_pixbuf(self, pb):
if pb is not None:
fname = tempfile.mktemp(suffix='.png', prefix='')
pb.save(fname, 'png')
self.upload_image(fname)
ftmp = tempfile.NamedTemporaryFile(suffix='.png', prefix='', delete=False)
pb.save_to_callback(ftmp.write, 'png')
self.upload_image(ftmp.name)
else:
self.show_error('Unable to get screenshot')

Expand All @@ -171,7 +174,18 @@ class LookitApp:
self.config.get('Upload', 'url'),
)
elif proto == 'Imgur':
notification = pynotify.Notification('Uploading image', 'Uploading image to Imgur')
notification.show()
success, data = uploader.upload_file_imgur(image)
try:
f = open(LOG_FILE, 'ab')
f.write(time.ctime() + ' Uploaded screenshot to Imgur: ' + data['original_image'] + '\n')
f.write('Delete url: ' + data['delete_page'] + '\n')
except IOError, e:
pass
finally:
f.close()
notification.close()
elif proto == 'None':
success = True
else:
Expand All @@ -191,15 +205,22 @@ class LookitApp:
'http://is.gd/api.php?longurl={0}'
.format(url)).readline()
print "URL Shortened:", url
if self.config.get('General', 'trash'):
if self.config.getboolean('General', 'trash'):
os.remove(os.path.abspath(image))
else:
# newimage =
try:
os.rename(os.path.abspath(image),
os.path.join(self.config.get( \
'General', 'savedir'), image))
except OSError:
timestamp = time.strftime('%Y-%m-%d_%H-%M-%S')
filename = timestamp + '.png'
destination = os.path.join(self.config.get('General', 'savedir'), filename)
i = 0
while os.path.exists(destination):
filename = timestamp + '_' + str(i) + '.png'
destination = os.path.join(self.config.get('General', 'savedir'), filename)
i += 1
shutil.move(image, destination)
image = destination
except IOError:
print "Error moving file"

clip = gtk.Clipboard()
Expand Down
5 changes: 4 additions & 1 deletion src/uploader.py
Expand Up @@ -112,7 +112,10 @@ def upload_file_imgur(f):
print 'Error: Imgur not supported'
i = ImgurUploader()
i.upload(f)
return True, i.mapping
if not 'error_msg' in i.mapping:
return True, i.mapping
else:
return False, i.mapping.get('error_msg')

def upload_file_ubuntuone(f):
pass

0 comments on commit c5d47d7

Please sign in to comment.