Created
September 20, 2015 12:58
-
-
Save doismellburning/5a30b1304a602d191bed to your computer and use it in GitHub Desktop.
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/python | |
from __future__ import absolute_import, division, print_function, unicode_literals | |
import csv | |
import subprocess | |
import sys | |
FILENAME = 'redirection.csv' | |
FLAGS = '--profile doismellburning' # FIXME | |
BUCKETNAME = 'blog.doismellburning.co.uk' | |
with open(FILENAME, 'r') as csvfile: | |
reader = csv.reader(csvfile) | |
for row in reader: | |
if len(row) != 2: | |
print("Found a row in %s that did not have exactly two fields: %s" % (FILENAME, row)) | |
sys.exit(1) | |
(from_url, to_url) = row | |
command = "aws {flags} s3 cp --website-redirect {to_url} {empty_file_path} s3://{bucket}{from_url}".format(flags=FLAGS, to_url=to_url, from_url=from_url, bucket=BUCKETNAME, empty_file_path=FILENAME) | |
# Yes I was gloriously lazy there and just sent a copy of the redirection file... | |
print("Redirecting from {from_url} to {to_url}".format(from_url=from_url, to_url=to_url)) | |
subprocess.check_output(command, shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment