Created
April 7, 2016 00:53
-
-
Save nottrobin/eb9d223500fe9e1a9b65ec4ffff440b5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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