Created
August 3, 2012 02:40
-
-
Save stephenmcd/3243788 to your computer and use it in GitHub Desktop.
Quick cache stats scraper using django-debug-toolbar's cache panel.
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
#!/usr/bin/env python | |
import os | |
import sys | |
import urllib | |
name, url, num = sys.argv[1:] | |
print name, url, num | |
first = not os.path.exists("output.csv") | |
f = open("output.csv", "a") | |
for i in range(int(num)): | |
html = urllib.urlopen(url).read().split("id=\"djDebugCachePanel")[1] \ | |
.split("<tbody>")[0].split("</tbody>")[0] | |
lines = [l.split(">")[1].split("<")[0].split("&")[0] for l in | |
html.splitlines() if l.strip().startswith(("<th", "<td"))][:-5] | |
headings = ["Name"] + lines[::2] | |
values = [name] + lines[1::2] | |
if first and i == 0: | |
f.write(",".join(headings) + "\n") | |
f.write(",".join(values) + "\n") | |
f.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: