Skip to content

Instantly share code, notes, and snippets.

@bmount
Created December 21, 2011 11:05
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 bmount/1505634 to your computer and use it in GitHub Desktop.
Save bmount/1505634 to your computer and use it in GitHub Desktop.
Bulk upload directory tree photo galleries to wordpress via RSS
# 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).
@bmount
Copy link
Author

bmount commented Jan 8, 2012

#Thumbnail template:

<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
    <channel>
        <title>Nob Hill Association Photo Galleries</title>
        <link>http://nobhillassociation.org</link>
        <description>Nob Hill 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'] %}

                <a href='{{ item }}'><img height="100" width="150" src="{{ item }}" alt="{{ item }}" /> </a>
                {% endfor %}
            </description>
        </item>
        {% endfor %}
    </channel>
</rss>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment