White House petitions don't have an API yet so I wrote something quick and dirty for a specific petition in reply to a tweet by @PogoWasRight.
This thing scrapes the petition's signatures and produces histograms by state and city as a javascript file called histograms.js
.
This gist contains a snapshot copy of that file (generated when there were ~32K signatures)
This means you can either clone the gist and view index.html
, or simply use Mike Bostock's magic gist viewer.
histograms.js
yourselfsudo apt-get install python3 python3-bs4
INITIAL_URL
at whphist.py
if you're interested in some other White House petition../whphist.py > histograms.json
fetches all signature pages from petition site.
This may take a while. If your network connection fails (happens to us in the 3rd world quite often), do
mv histograms.json old_hist.json
and then ./whphist.py old_hist.json > histograms.json
to continue where you've left../json2js.py < histograms.json > histograms.js
this tidies up things a bit, and generates a javascript file easier to work with.whphist.py
has zero user interface at the moment (even the URL is hard-wired). Should be friendlier. Command line? Web front-end? You be the judge.histograms.js
also contains breakdown to cities, so you can make pie slices explode and what not :)xxxxxxxxxx
<meta charset="utf-8">
<!-- <html lang="en"> -->
<!-- <head> -->
<style>
body {
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 10px;
}
.arc path {
stroke: #fff;
}
</style>
<!-- </head>
<body> -->
<h1 align="center" id="desc"></h1>
<p align="center" id="explanation">Move mouse over pie slices for details</p>
<div id="chart-div" style="text-align:center"></div>
<p align="center" id="info">Data: <a href="https://petitions.whitehouse.gov/petition/remove-united-states-district-attorney-carmen-ortiz-office-overreach-case-aaron-swartz/RQNrG1Ck">White House petition</a>. <a href="https://gist.github.com/4544529">Code</a>.</p>
<script type='text/javascript' src="https://cdn.jsdelivr.net/npm/d3@12.10.3/d3.min.js"></script>
<script type='text/javascript' src="histograms.js"></script>
<script type='text/javascript' src="piechart.js"></script>
<!-- </body>
</html> -->
Updated missing url https://raw.github.com/mbostock/d3/master/d3.min.js to https://cdn.jsdelivr.net/npm/d3@12.10.3/d3.min.js
https://raw.github.com/mbostock/d3/master/d3.min.js