Skip to content

Instantly share code, notes, and snippets.

@migurski
Created January 30, 2014 06:48
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 migurski/8703759 to your computer and use it in GitHub Desktop.
Save migurski/8703759 to your computer and use it in GitHub Desktop.
Scripts used in the creation of the new Code for America website.
from requests import get
from urlparse import urlparse
from csv import DictWriter, writer
with open('wordpress-paths.txt') as file, open('site-paths.csv', 'w') as out:
cols = 'original_path', 'original_code', \
'live_path', 'live_code', \
'new_path', 'new_code', \
'status', 'hits'
results = writer(out)
results.writerow(cols)
for line in list(file)[:]:
live_code, live_path, new_code, new_path = '', '', '', ''
hits, method, original_path, original_code = line.split()
if original_code[0] not in ('2', '3'):
continue
print hits, original_path
try:
url = 'http://www.codeforamerica.org' + original_path
got = get(url)
live_code = got.status_code
_, live_host, live_path, _, _, _ = urlparse(got.url)
if live_host != 'www.codeforamerica.org':
live_path = 'http://' + live_host + live_path
dir = '/~migurski/Codeforamerica.org'
url = 'http://localhost' + dir + original_path
got = get(url)
new_code = got.status_code
_, new_host, new_path, _, _, _ = urlparse(got.url)
if new_host != 'localhost':
new_path = 'http://' + new_host + new_path
elif new_path.startswith(dir):
new_path = new_path[len(dir):]
if live_code == new_code:
status = 'OK'
elif new_code == 404:
if new_path != original_path:
status = 'Missing'
elif live_path == new_path + '/':
status = 'Missing'
elif live_path != original_path:
status = 'Needs redirect'
else:
status = 'Missing'
else:
status = '?'
except Exception, e:
status = 'Error: ' + unicode(e)
results.writerow([locals().get(col) for col in cols])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment