Get all posts from pinboard:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import urllib2

# Parameters.
backupfile = 'YOUR FILE PATH'
pinboard_api = 'https://api.pinboard.in/v1/'

# Get the user's authentication token
token = 'YOUR API TOKEN'

# Set up a new bookmarks file
bookmarkfile = open(backupfile, 'w')

# Get all the posts from Pinboard
u = urllib2.urlopen(pinboard_api + 'posts/all?auth_token=' + token)
bookmarkfile.write(u.read())
bookmarkfile.close()

Search photos with the same month and day of creation on Mac:

 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
import os
import sys
import shutil
import subprocess
from datetime import date

if len(sys.argv)>1:
    month, day = int(sys.argv[1][:2]), int(sys.argv[1][2:])
    today = date(date.today().year, month, day)
else:
    today = date.today()

dat = 'InRange(kMDItemContentCreationDate,"$time.iso({})","$time.iso({})")'
inrange = []
for year in range(today.year-9,today.year+1):
    s = '{}-{}T00:00:00Z'.format(year, today.isoformat()[5:])
    e = '{}-{}T23:59:59Z'.format(year, today.isoformat()[5:])
    inrange.append(dat.format(s, e))
condition = '\'({}) && (_kMDItemGroupId = 13)\''.format(' || '.join(inrange))
cmd = ['mdfind', '-onlyin', 'YOUR PHOTO FOLDER PATH', condition]

output = subprocess.check_output(' '.join(cmd), shell=True)
paths = output.split("\n")[:-1]

dst = "/tmp/{}/".format(today.isoformat())
if os.path.isdir(dst):
    shutil.rmtree(dst)
os.mkdir(dst)
for img in paths:
    # shutil.copy(img, dst)
    os.link(img, dst+os.path.basename(img))

subprocess.call("open {}".format(dst), shell=True)

Use Google Maps API to retrieve geographical information:

1
2
3
4
5
import googlemaps

client = googlemaps.Client('YOUR API KEY')
result0 = client.geocode('ZIPCODE/CITY/ADDRESS/DICT')
result1 = client.distance_matrix([ORIGIN LIST], [DESTINATION LIST])

Connect to SQL Server via pyodbc:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import pyodbc

driver = 'SQL Server'
server = 'YOUR SERVER ADDRESS'
database = 'YOUR DATABASE NAME'
username = 'YOUR USERNAME'
password = 'YOUR PASSWORD'

connStr = 'DRIVER={{{}}};SERVER={};DATABASE={};UID={};PWD={}'.\
    format(driver, server, database, username, password)
conn = pyodbc.connect(connStr)
cursor = conn.cursor()
sqlStr = 'YOUR SQL COMMAND'
cursor.execute(sqlStr)

for row in cursor:
    print row[0]

conn.close()