-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflickr
31 lines (25 loc) · 916 Bytes
/
flickr
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
#!/usr/bin/python
from appscript import app, its, k
import re
import sys
def b58encode(n):
chars = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
basecount = len(chars)
b58 = []
while (n >= basecount):
(div, mod) = divmod(n, basecount)
b58.insert(0, chars[mod])
n = div
if (n > 0):
b58.insert(0, chars[n])
return ''.join(b58)
numSafari = app('System Events').processes[its.name == 'Safari'].count(each=k.item)
numChrome = app('System Events').processes[its.name == 'Google Chrome'].count(each=k.item)
if numSafari > 0:
url = app('Safari').documents[0].URL.get()
elif numChrome > 0:
frontIndex = app('Google Chrome').windows[1].active_tab_index.get()
url = app('Google Chrome').windows[1].tabs[frontIndex].URL.get()
ids = re.findall(r'flickr\.com/photos/.*/(\d+)/?', url)
shortflickr = 'http://flic.kr/p/%s' % b58encode(int(ids[0]))
sys.stdout.write(shortflickr)