Once upon a time with Flickr API
After upgrading to Hardy, today is my first chance to run jUploadr to upload new photos to Flickr. But unfortunately, I couldn't see photo thumbnails. Actually, they were just black.
Then I tried jUploadr 1.2 alpha 1 and the result was similar.
So I had to find alternative solution other than jUploadr due to a bug in X.org. Anyway, I didn't find any good one so I decided to try flash uploader.
Flash uploader worked but it consumed my cpu. In addition, my firefox was locked in almost-freeze state for so long.
Eventually, I decided to write python script to upload batch of photos in command-line. I'm not alone and I'm not the first pythonian who try to do like this. I found Beej's Python Flickr API. This library looks promising and easy to install.
easy_install flickrapi
After that Python lets me import flickrapi. So the next step is authentication.
flickr = flickrapi.FlickrAPI(api_key, api_secret) token, frob = flickr.get_token_part_one(perms='write') if not token: raw_input('Please ENTER after you authorized this program') flickr.get_token_part_two((token, frob))
Note that you need __api_key__ and __api_secret__. Go to get it at Flickr Services. You need to obtain both api key and shared secret to let this script write to Flickr. After this point, we are ready to upload photo.
def progress(self, progress, done): if done: print ' done', else: print '\r%s%%' % progress, print 'uploading %s' % name flickr.upload(filename=name, title=os.path.basename(name), callback=progress) print
Below are the full source.
#!/usr/bin/python api_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' api_secret = 'XXXXXXXXXXXXXXXX' import os from optparse import OptionParser import flickrapi class App: def __init__(self): self.options, self.args = self.parse_args() def parse_args(self): parser = OptionParser() parser.add_option('--title', dest='title', default=None, help='photo title') parser.add_option('--description', dest='description', default='', help='photo description') parser.add_option('-t', '--tags', dest='tags', default='', help='photo tags') parser.add_option('--public', dest='public', action='store_true', help='is public?') parser.add_option('--family', dest='family', action='store_true', help='is family?') parser.add_option('--friend', dest='friend', action='store_true', help='is friend?') return parser.parse_args() def authenticate(self): token, frob = self.flickr.get_token_part_one(perms='write') if not token: raw_input('Please ENTER after you authorized this program') self.flickr.get_token_part_two((token, frob)) def progress(self, progress, done): if done: print ' done', else: print '\r%s%%' % progress, def upload_file(self, name): params = { 'filename': name, 'title': self.options.title or os.path.basename(name), 'description': self.options.description, 'tags': self.options.tags, 'is_public': int(self.options.public or False), 'is_family': int(self.options.family or False), 'is_friend': int(self.options.friend or False), 'callback': self.progress, } print 'uploading %s' % name self.flickr.upload(**params) print def run(self): self.flickr = flickrapi.FlickrAPI(api_key, api_secret) self.authenticate() for name in self.args: self.upload_file(name) if __name__ == '__main__': app = App() app.run()
And I like to run.
flickr.py -t home 101MSDCF/*.JPG








cool !!! ...
P.S. A U realy girl?
U need antivirus?
Post new comment