Skip to content

Instantly share code, notes, and snippets.

@doismellburning
Created September 20, 2015 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doismellburning/5a30b1304a602d191bed to your computer and use it in GitHub Desktop.
Save doismellburning/5a30b1304a602d191bed to your computer and use it in GitHub Desktop.
#!/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