Created
December 21, 2011 11:05
-
-
Save bmount/1505634 to your computer and use it in GitHub Desktop.
Bulk upload directory tree photo galleries to wordpress via RSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a jinja2 xml template compatible with Wordpress RSS | |
# import. Based on Flickr GeoRSS format. | |
# wp rss import v 0.2 did not like couple of other | |
# variations on this. | |
# takes dictionary like {"directory/subdir":[list, of, filenames], | |
# "dir2/subdir":[other, file, names]} | |
<?xml version="1.0" encoding="iso-8859-1"?> | |
<rss version="2.0"> | |
<channel> | |
<title>Example Photo Galleries</title> | |
<link>http://example.org</link> | |
<description>Example Photo Collection</description> | |
<lastBuildDate>Wed, 21 Dec 2011 00:26:16 GMT</lastBuildDate> | |
<generator>jinja2</generator> | |
{% for entry in entries %} | |
<item> | |
<title>{{ entry }}</title> | |
<description> | |
{% for item in entries[entry]['image_links'] %} | |
<p><img src="{{ item }}" alt="{{ item }}" /> </p> | |
{% endfor %} | |
</description> | |
</item> | |
{% endfor %} | |
</channel> | |
</rss> | |
# entries are the output of python os.walk('/the/directory') | |
# serialized as json. Pipe output to file and upload via | |
# wordpress web interface (tools -> import -> RSS) | |
import json | |
import jinja2 | |
jinja_template = jinja2.Template(open('above_string_as_template.jinja.xml').read()) | |
f = json.load(open('above_dirs_as.json')) | |
base_url = "http://example.org/wp-content/uploads/Galleries/" | |
entries={} | |
for i in f[1:]: | |
if i: | |
entries[i[0].split('/')[1]] = {"image_links":[base_url+ll[2:] for ll in i]} | |
print jinja_template.render(entries=entries) | |
# Assumptions: The gallery directory has been recursively copied | |
# to some location like that of `base_url` (suggest `upload` dir for | |
# simplicity). |
Author
bmount
commented
Jan 8, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment