forked from drdrang/flickr-stuff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathup2flickr
executable file
·51 lines (41 loc) · 1.2 KB
/
up2flickr
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
from flickrapi import FlickrAPI
from os.path import basename, splitext
import sys
import getopt
from subprocess import call
usage = """Usage: up2flickr [options] [files]
Options:
-p make the photos public
-h show this help message
Upload image files to Flickr. The images will be private to
friends and family by default."""
# Flickr parameters
fuser = 'Flickr username'
key = 'Get key from Flickr'
secret = 'Get secret from Flickr'
# Get the command line options.
try:
options, filenames = getopt.getopt(sys.argv[1:], 'ph')
except getopt.GetoptError, err:
print str(err)
sys.exit(2)
# Set the option values.
public = 0 # default
for o, a in options:
if o == '-p':
public = 1
else:
print usage
sys.exit()
# Upload the files on the command line.
flickr = FlickrAPI(api_key=key, secret=secret)
for fn in filenames:
print "Uploading %s..." % fn
t = splitext(basename(fn))[0] # file name w/o extension
response = flickr.upload(filename=fn, title=t,\
is_public=public, format='etree')
photoID = response.find('photoid').text
photoURL = 'http://www.flickr.com/photos/%s/%s/' % (fuser, photoID)
print " %s" % photoURL
call(['open', photoURL])