Skip to content

Instantly share code, notes, and snippets.

@nottrobin
Created April 7, 2016 00:53
Show Gist options
  • Select an option

  • Save nottrobin/eb9d223500fe9e1a9b65ec4ffff440b5 to your computer and use it in GitHub Desktop.

Select an option

Save nottrobin/eb9d223500fe9e1a9b65ec4ffff440b5 to your computer and use it in GitHub Desktop.
import json
with open('redirects.yaml') as redirects_file:
redirects = json.load(redirects_file)
new_redirects = {}
for request, target in redirects.iteritems():
if '?' in request:
# Remove anything with a question mark (it wont work)
continue
if request[-1:] == '/' and request[:-1] in redirects:
new_request = request[:-1] + '/?'
new_redirects[new_request] = target
elif request + '/' not in redirects:
new_redirects[request] = target
print json.dumps(new_redirects, sort_keys=True, indent=4, separators=(',', ': '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment