Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 49 lines (34 sloc) 1.407 kb
627a337 @jcarbaugh initial commit
jcarbaugh authored
1 from flickrapi import shorturl
2 import datetime
3 import flickrapi
4 import pbserver
5
6 def upload(path):
7
8 API_KEY = pbserver.config.get('flickr', 'api_key')
9 API_SECRET = pbserver.config.get('flickr', 'api_secret')
10 TOKEN = pbserver.config.get('flickr', 'auth_token')
11
12 if not TOKEN:
13 raise ValueError('invalid or missing token')
14
15 flickr = flickrapi.FlickrAPI(API_KEY, API_SECRET, token=TOKEN)
16
17 params = {
18 'filename': path,
19 'title': '%s' % datetime.datetime.now(),
20 'is_public': pbserver.config.get('flickr', 'is_public'),
21 'format': 'etree',
22 }
23
24 tags = pbserver.config.get('flickr', 'tags')
25 if tags:
26 params['tags'] = tags
27
28 resp = flickr.upload(**params)
29 photo_id = resp.find('photoid').text
30
31 photoset_id = pbserver.config.get('flickr', 'photoset')
32 if photoset_id:
33 flickr.photosets_addPhoto(photoset_id=photoset_id, photo_id=photo_id)
34
35 return shorturl.url(photo_id)
36
37
38 if __name__ == '__main__':
39
40 API_KEY = pbserver.config.get('flickr', 'api_key')
41 API_SECRET = pbserver.config.get('flickr', 'api_secret')
42
43 flickr = flickrapi.FlickrAPI(API_KEY, API_SECRET)
44
45 (token, frob) = flickr.get_token_part_one(perms='write')
46 if not token:
47 raw_input("Press ENTER after you authorized this program")
48
49 print "auth_token:", flickr.get_token_part_two((token, frob))
Something went wrong with that request. Please try again.