Skip to content

Instantly share code, notes, and snippets.

@anmsid
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anmsid/a44bad6c507eb0a9d18b to your computer and use it in GitHub Desktop.
Save anmsid/a44bad6c507eb0a9d18b to your computer and use it in GitHub Desktop.
Simple script utilizing google gdata photo service, for those who are lazy enough to create a WordPress content and just want to dump everything from their Picasaweb album.
#!/usr/bin/env python
import gdata.photos.service
import argparse
"""
For those who are lazy enough to create a wordpress content and just want to dump everything from their Picasaweb album.
Usage: ./pwphotos.py -u PICASAWEB_USER -a PICASAWEB_ALBUM
Output will be printed to stdout, you can simply redirect it to a file > out.txt or just copy paste to WordPress (Text mode)
"""
gd_client = gdata.photos.service.PhotosService()
parser = argparse.ArgumentParser(description="Picasaweb -> Wordpress content")
parser.add_argument("--user", "-u", required=True, help="Picasaweb username")
parser.add_argument("--album", "-a", required=True, help="Name of the album")
parser.add_argument("--authkey", "-k", required=False, help="Authkey of unlisted album")
parser.add_argument("--size", "-s", required=False, type=int, help="Image size")
parser.add_argument("--paging", "-p", required=False, type=int, help="Number of image per-page")
parser.add_argument("--caption", "-c", required=False, action="store_true", help="Include photo caption")
options = parser.parse_args()
img_size = options.size if options.size else 800
if options.authkey:
photos = gd_client.GetFeed('/data/feed/api/user/%s/album/%s?authkey=%s&kind=photo' %(options.user, options.album, options.authkey))
else:
photos = gd_client.GetFeed('/data/feed/api/user/%s/album/%s?kind=photo' %(options.user, options.album))
for i, p in enumerate(photos.entry):
urll = p.media.content[0].url.split('/')
urll.insert(-1,"s%d" %(img_size))
if options.caption and p.summary.text:
s = '[caption id="" align="aligncenter" width="%d"]<img src="%s" alt="%s" width="%d" class="aligncenter" />%s[/caption]' %(img_size, '/'.join(urll), p.title.text, img_size, p.summary.text)
else:
s = '<img src="%s" alt="%s" width="%d" class="aligncenter" />' %('/'.join(urll), p.title.text, img_size)
print s
if options.paging:
if (i+1) % options.paging == 0:
print '<!--nextpage-->'
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment