Last active
January 8, 2020 15:28
-
-
Save 1davidmichael/1c35939c6dfb59d59c65e7a1c4ebcbe3 to your computer and use it in GitHub Desktop.
Convert CSV into Apache Rewrite Map txt file
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
#!/usr/bin/env python3 | |
# Usage | |
''' | |
python convert_csv_to_rewrite_map.py file.csv > rewrite_map.txt | |
''' | |
import csv | |
import sys | |
from urllib.parse import urlparse | |
csv_redirects = sys.argv[1] | |
with open(csv_redirects) as csv_file: | |
csv_reader = csv.reader(csv_file, delimiter=',') | |
for row in csv_reader: | |
parsed = urlparse(row[0]) | |
print(f"{ parsed.path } {row[1]}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment