Skip to content

Instantly share code, notes, and snippets.

@Ceasar
Created August 12, 2012 22:32
Show Gist options
  • Save Ceasar/3334992 to your computer and use it in GitHub Desktop.
Save Ceasar/3334992 to your computer and use it in GitHub Desktop.
Proof of concept code to solve the problem of how to build a sitemap or file system tree.
import os
from pprint import pprint
MAP = {}
CHILDREN_KEY = 'children'
for path, _, filenames in os.walk('./templates'):
path = path.split("/")[2:]
spot = MAP
for p in path[:-1]:
spot = spot[p]
try:
spot[path[-1]] = {CHILDREN_KEY: filenames}
except IndexError:
spot[CHILDREN_KEY] = filenames
pprint(MAP, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment