summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Macken <lmacken@redhat.com>2011-03-12 12:22:30 -0500
committerLuke Macken <lmacken@redhat.com>2011-03-12 12:22:30 -0500
commit03f27ccdc8e1e09206c09682040d96e5e03a9c01 (patch)
tree55b28d08fbbc3b6dbf9f8df91d24c5715a38818d
parentf4281bdd8d77feb072151d387e5fbc39dda177f1 (diff)
downloadphotobooth-03f27ccdc8e1e09206c09682040d96e5e03a9c01.tar.gz
photobooth-03f27ccdc8e1e09206c09682040d96e5e03a9c01.tar.xz
photobooth-03f27ccdc8e1e09206c09682040d96e5e03a9c01.zip
Use surl to shorten the URLHEADmaster
-rw-r--r--photobooth.py26
1 files changed, 11 insertions, 15 deletions
diff --git a/photobooth.py b/photobooth.py
index 37d3d2f..c4118dd 100644
--- a/photobooth.py
+++ b/photobooth.py
@@ -1,13 +1,12 @@
#!/usr/bin/python
-# sxsw.py - version 0.2
-# Requires: python-imaging, qrencode, gphoto2
+# photobooth.py - version 0.3
+# Requires: python-imaging, qrencode, gphoto2, surl
# Author: Luke Macken <lmacken@redhat.com>
# License: GPLv3
import os
+import surl
import Image
-import urllib
-import simplejson
import subprocess
from uuid import uuid4
@@ -39,6 +38,9 @@ gphoto_config = {
'/main/capturesettings/zoom': 70, # zoom factor
}
+# The URL shortener to use
+shortener = 'tinyurl.com'
+
class PhotoBooth(object):
def initialize(self):
@@ -65,8 +67,8 @@ class PhotoBooth(object):
url = self.upload(image)
print "Generating QRCode..."
qrcode = self.qrencode(url)
- print "Generating TinyURL..."
- tiny = self.tinyurl(url)
+ print "Shortening URL..."
+ tiny = self.shorten(url)
print "Generating HTML..."
html = self.html_output(url, qrcode, tiny)
subprocess.call('firefox "%s"' % html, shell=True)
@@ -99,15 +101,9 @@ class PhotoBooth(object):
qrcode_size, qrcode, url), shell=True)
return qrcode
- def tinyurl(self, url):
- """ Generate a tinyurl for a given URL """
- data = urllib.urlopen("http://json-tinyurl.appspot.com/?url=%s" % url).read()
- json = simplejson.loads(data)
- if not json['ok']:
- print 'ERROR: There was a problem generating a tinyurl'
- print json
- return url
- return json['tinyurl']
+ def shorten(self, url):
+ """ Generate a shortened URL """
+ return surl.services.supportedServices()[shortener].get({}, url)
def html_output(self, image, qrcode, tinyurl):
""" Output HTML with the image, qrcode, and tinyurl """