Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:drdrang/flickr-stuff

  • Loading branch information...
commit d430c5cb98bb321f77ab2d9c68b4e1a440a1ca22 2 parents 2c8d74d + 8f1298e
@drdrang authored
Showing with 181 additions and 33 deletions.
  1. +100 −10 Flickr.textexpander
  2. +9 −4 README.md
  3. +16 −12 currentflickr.py
  4. +56 −7 snapflickr
View
110 Flickr.textexpander
@@ -23,7 +23,7 @@
<key>label</key>
<string>Flickr large image URL</string>
<key>lastUsed</key>
- <date>2011-07-30T21:36:35Z</date>
+ <date>2012-02-22T04:44:59Z</date>
<key>modificationDate</key>
<date>2011-07-30T04:42:33Z</date>
<key>plainText</key>
@@ -37,7 +37,7 @@ sys.stdout.write(currentFlickrURL('Large'))
<key>snippetType</key>
<integer>3</integer>
<key>useCount</key>
- <integer>9</integer>
+ <integer>10</integer>
<key>uuidString</key>
<string>5C1F2B90-C76B-4F98-BDF5-706630FCD74E</string>
</dict>
@@ -73,6 +73,36 @@ sys.stdout.write(currentFlickrURL('Small'))
</dict>
<dict>
<key>abbreviation</key>
+ <string>;320</string>
+ <key>abbreviationMode</key>
+ <integer>0</integer>
+ <key>creationDate</key>
+ <date>2011-07-30T03:36:37Z</date>
+ <key>flags</key>
+ <integer>2</integer>
+ <key>label</key>
+ <string>Flickr small 320 image URL</string>
+ <key>lastUsed</key>
+ <date>2012-04-07T04:53:44Z</date>
+ <key>modificationDate</key>
+ <date>2012-04-07T04:53:03Z</date>
+ <key>plainText</key>
+ <string>#!/usr/bin/python
+
+import sys
+from currentflickr import currentFlickrURL
+
+sys.stdout.write(currentFlickrURL('Small 320'))
+</string>
+ <key>snippetType</key>
+ <integer>3</integer>
+ <key>useCount</key>
+ <integer>9</integer>
+ <key>uuidString</key>
+ <string>9B8423F4-996A-41E6-8318-288D58BAF282</string>
+ </dict>
+ <dict>
+ <key>abbreviation</key>
<string>;100</string>
<key>abbreviationMode</key>
<integer>0</integer>
@@ -133,6 +163,36 @@ sys.stdout.write(currentFlickrURL('Square'))
</dict>
<dict>
<key>abbreviation</key>
+ <string>;150</string>
+ <key>abbreviationMode</key>
+ <integer>0</integer>
+ <key>creationDate</key>
+ <date>2011-07-30T03:36:37Z</date>
+ <key>flags</key>
+ <integer>2</integer>
+ <key>label</key>
+ <string>Flickr large square image URL</string>
+ <key>lastUsed</key>
+ <date>2012-04-07T04:53:51Z</date>
+ <key>modificationDate</key>
+ <date>2012-04-07T04:52:26Z</date>
+ <key>plainText</key>
+ <string>#!/usr/bin/python
+
+import sys
+from currentflickr import currentFlickrURL
+
+sys.stdout.write(currentFlickrURL('Large Square'))
+</string>
+ <key>snippetType</key>
+ <integer>3</integer>
+ <key>useCount</key>
+ <integer>9</integer>
+ <key>uuidString</key>
+ <string>15BE2269-1E66-4EB0-97FD-EA0B03E01876</string>
+ </dict>
+ <dict>
+ <key>abbreviation</key>
<string>;original</string>
<key>abbreviationMode</key>
<integer>0</integer>
@@ -143,7 +203,7 @@ sys.stdout.write(currentFlickrURL('Square'))
<key>label</key>
<string>Flickr original image URL</string>
<key>lastUsed</key>
- <date>2011-08-01T01:05:19Z</date>
+ <date>2012-04-06T02:25:43Z</date>
<key>modificationDate</key>
<date>2011-07-30T04:42:53Z</date>
<key>plainText</key>
@@ -157,7 +217,7 @@ sys.stdout.write(currentFlickrURL('Original'))
<key>snippetType</key>
<integer>3</integer>
<key>useCount</key>
- <integer>12</integer>
+ <integer>77</integer>
<key>uuidString</key>
<string>F1FC32A9-468F-4266-833B-03BF4899DC36</string>
</dict>
@@ -173,7 +233,7 @@ sys.stdout.write(currentFlickrURL('Original'))
<key>label</key>
<string>Flickr medium 640 image URL</string>
<key>lastUsed</key>
- <date>2011-07-30T21:36:27Z</date>
+ <date>2012-04-07T04:16:40Z</date>
<key>modificationDate</key>
<date>2011-07-30T04:43:30Z</date>
<key>plainText</key>
@@ -187,12 +247,42 @@ sys.stdout.write(currentFlickrURL('Medium 640'))
<key>snippetType</key>
<integer>3</integer>
<key>useCount</key>
- <integer>112</integer>
+ <integer>254</integer>
<key>uuidString</key>
<string>03D04AED-76CC-4D96-89DC-B08FD1D70856</string>
</dict>
<dict>
<key>abbreviation</key>
+ <string>;800</string>
+ <key>abbreviationMode</key>
+ <integer>0</integer>
+ <key>creationDate</key>
+ <date>2010-07-22T19:40:28Z</date>
+ <key>flags</key>
+ <integer>2</integer>
+ <key>label</key>
+ <string>Flickr medium 800 image URL</string>
+ <key>lastUsed</key>
+ <date>2012-04-07T04:53:59Z</date>
+ <key>modificationDate</key>
+ <date>2012-04-07T04:51:55Z</date>
+ <key>plainText</key>
+ <string>#!/usr/bin/python
+
+import sys
+from currentflickr import currentFlickrURL
+
+sys.stdout.write(currentFlickrURL('Medium 800'))
+</string>
+ <key>snippetType</key>
+ <integer>3</integer>
+ <key>useCount</key>
+ <integer>254</integer>
+ <key>uuidString</key>
+ <string>6D73F9A9-2B56-42DF-9579-0BF423BBBE0D</string>
+ </dict>
+ <dict>
+ <key>abbreviation</key>
<string>;500</string>
<key>abbreviationMode</key>
<integer>0</integer>
@@ -203,7 +293,7 @@ sys.stdout.write(currentFlickrURL('Medium 640'))
<key>label</key>
<string>Flickr medium image URL</string>
<key>lastUsed</key>
- <date>2011-08-01T01:18:42Z</date>
+ <date>2012-04-07T04:54:15Z</date>
<key>modificationDate</key>
<date>2011-07-30T04:43:12Z</date>
<key>plainText</key>
@@ -217,7 +307,7 @@ sys.stdout.write(currentFlickrURL('Medium'))
<key>snippetType</key>
<integer>3</integer>
<key>useCount</key>
- <integer>121</integer>
+ <integer>140</integer>
<key>uuidString</key>
<string>F45CF6FA-93EE-42FB-B359-FB1462C87DE4</string>
</dict>
@@ -233,7 +323,7 @@ sys.stdout.write(currentFlickrURL('Medium'))
<key>label</key>
<string>flic.kr link</string>
<key>lastUsed</key>
- <date>2011-08-01T01:18:20Z</date>
+ <date>2012-01-17T05:42:51Z</date>
<key>modificationDate</key>
<date>2011-08-01T01:17:29Z</date>
<key>plainText</key>
@@ -247,7 +337,7 @@ sys.stdout.write(currentFlickrURL('Short'))
<key>snippetType</key>
<integer>3</integer>
<key>useCount</key>
- <integer>36</integer>
+ <integer>48</integer>
<key>uuidString</key>
<string>01A112FE-204F-475A-9CAB-198A3AFB77CC</string>
</dict>
View
13 README.md
@@ -15,11 +15,15 @@ getFlickrToken authorizes any program you've registered with Flickr (http://www.
## snapflickr ##
-snapflickr takes a snapshot of your screen (similar to the builtin ⇧⌘4), saves a copy to your Desktop, and uploads a copy to your Flickr account. You provide a file name and (optionally) a description before taking the snapshot.
+snapflickr takes a snapshot of your screen (similar to the builtin ⇧⌘4), saves a copy to your Desktop, and uploads a copy to your Flickr account.
-![snapflickr dialog box]( http://farm6.static.flickr.com/5074/5914101080_b6dc03beba_o.jpg)
+When snapflickr is run, it turns the cursor into a camera, ready to take a snapshot of any window (you can change it to take a snapshot of an arbitrary rectangle by pressing the spacebar). After the snapshot is taken, a window appears in which you provide a file name and (optionally) a description.
-It requires [Carsten Blüm's Pashua application][1] and its accompanying Python library. The use is described in more detail [here][3].
+![snapflickr dialog box](http://farm8.staticflickr.com/7065/6773443376_b9d6f3dd48_o.jpg)
+
+By default, the snapshot is uploaded to your Flickr account, but if you click the "Local file only" checkbox, there's no upload. If the image is uploaded to Flickr, its page is opened in the default browser and an `<img>` tag for the chosen size is put on the clipboard.
+
+It requires [Carsten Blüm's Pashua application][1] and its accompanying Python library. The use is described in more detail [here][3]. It also requires the [Python Imaging Library][6] to add a desktop background color to window screenshots.
Near the top of snapflickr is a section of Flickr parameters:
@@ -73,6 +77,7 @@ These must be customized with the appropriate username and API info.
[1]: http://www.bluem.net/en/mac/pashua/
[2]: http://stuvel.eu/flickrapi
-[3]: http://www.leancrew.com/all-this/2011/07/screenshotupload-utility-now-with-flickr/
+[3]: http://www.leancrew.com/all-this/2012/02/snapflickr-update/
[4]: http://appscript.sourceforge.net/
[5]: http://microcosmsoftware.com/playsound/
+[6]: http://www.pythonware.com/products/pil/
View
28 currentflickr.py 100644 → 100755
@@ -61,15 +61,18 @@ def currentFlickrTitle():
def currentFlickrURL(kind):
'''Return a URL for the Flickr image currently showing in the browser.
-
- The string parameter "kind" can be either "Short" or one of the standard
- Flickr image sizes: "Original", "Large", "Medium 640", "Medium", "Small",
- "Thumbnail", or "Square". If it's Short, the function will return a
- flic.kr URL for the image page. If it's one of the others, the function
- will return the URL of the image of that size, if available.
-
- The function works through Apple Events and supports only the Safari and
- Chrome browsers.'''
+
+ The string parameter "kind" can be either "Short" or one of the
+ standard Flickr image sizes: "Original", "Large", "Medium 800",
+ "Medium 640", "Medium", "Small 320", "Small", "Thumbnail", "Large
+ Square", or "Square". If it's Short, the function will return a
+ flic.kr URL for the image page. If it's one of the others, the
+ function will return the URL of the image of that size, if
+ available.
+
+ The function works through Apple Events and supports only the Safari
+ and Chrome browsers.'''
+
# Flickr parameters
fuser = 'Flickr username'
@@ -77,9 +80,10 @@ def currentFlickrURL(kind):
secret = 'Get secret from Flickr'
# Make sure we're asking for a legitimate kind.
- kind = kind.capitalize()
- kinds = ["Short", "Original", "Large", "Medium 640",
- "Medium", "Small", "Thumbnail", "Square"]
+ kind = ' '.join([x.capitalize() for x in kind.split()])
+ kinds = ["Short", "Original", "Large", "Medium 800", "Medium 640",
+ "Medium", "Small 320", "Small", "Thumbnail",
+ "Large Square", "Square"]
if kind not in kinds:
return "Not a legitimate kind of URL"
View
63 snapflickr
@@ -2,14 +2,17 @@
import Pashua
from flickrapi import FlickrAPI
+import Image
import sys, os
-from subprocess import call
+import subprocess
import re
# Local parameters
-extension = "jpg"
+extension = "png"
localdir = os.environ['HOME'] + "/Desktop"
-tempfile = "temp.jpg"
+tempfile = "temp.png"
+bgcolor = (61, 101, 156)
+margin = (25, 5, 25, 35)
# Flickr parameters
fuser = 'your Flickr username'
@@ -44,6 +47,16 @@ descl.default = Description:
descl.x = 10
descl.y = 95
+# Size radiobutton properties
+radio.type = radiobutton
+radio.label = Size of <img>:
+radio.option = Original
+radio.option = Large
+radio.option = Medium 640
+radio.option = Medium 500
+radio.default = Medium 640
+radio.x = 380
+radio.y = 50
# Local files checkbox properties
lf.type = checkbox
@@ -53,7 +66,7 @@ lf.y = 5
# Default button
db.type = defaultbutton
-db.label = Rename
+db.label = Save
# Cancel button
cb.type = cancelbutton
@@ -63,16 +76,35 @@ cb.type = cancelbutton
os.chdir(localdir)
# Capture a portion of the screen and save it to a temporary file.
-call(["screencapture", "-iW", "-t", extension, tempfile])
+subprocess.call(["screencapture", "-iW", "-t", extension, tempfile])
+
+# Exit if the user canceled the screencapture.
+if not os.access(tempfile, os.F_OK):
+ sys.exit()
# Open the dialog box and get the input.
dialog = Pashua.run(conf)
if dialog['cb'] == '1':
+ os.remove(tempfile)
sys.exit()
# Rename the temporary file.
fn = '%s.%s' % (dialog['fn'], extension)
-call(["mv", tempfile, fn])
+subprocess.call(["mv", tempfile, fn])
+
+# Add a desktop background if it's a shadowed window screenshot.
+snap = Image.open(fn)
+if snap.mode == 'RGBA':
+ # Crop it to a more reasonable size,
+ # and paste it over a solid-colored background.
+ cropbox = (margin[0],
+ margin[1],
+ snap.size[0]-margin[2],
+ snap.size[1]-margin[3])
+ snap = snap.crop(cropbox)
+ bg = Image.new('RGB', snap.size, bgcolor)
+ bg.paste(snap, None, snap)
+ bg.save(fn)
# Unless this is just a local file...
if dialog['lf'] != '1':
@@ -91,5 +123,22 @@ if dialog['lf'] != '1':
flickr.photosets_addPhoto(photo_id = photoID, photoset_id = screenshotsID)
# Open the photo page in the default browser.
- call(['open', photoURL])
+ subprocess.call(['open', photoURL])
+
+ # Put an img element on the clipboard for the selected size of the image.
+ size = dialog['radio']
+ if size == 'Medium 500': size = 'Medium'
+ flickr = FlickrAPI(api_key=key, secret=secret)
+ etree = flickr.photos_getSizes(photo_id = photoID, format = 'etree')
+ for i in etree[0]:
+ if i.attrib['label'] == size:
+ tag = '<img class="ss" src="%s" alt="%s" title="%s" />' %\
+ (i.attrib['source'], dialog['fn'], dialog['fn'])
+ subprocess.Popen('pbcopy', stdin=subprocess.PIPE).communicate(tag)
+ sys.exit()
+
+ # If the selected size wasn't available.
+ tag = '<img src="%s" alt="%s" title="%s" />' %\
+ ('size_not_found', dialog['fn'], dialog['fn'])
+ subprocess.Popen('pbcopy', stdin=subprocess.PIPE).communicate(tag)
Please sign in to comment.
Something went wrong with that request. Please try again.