-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbillscraper.php
46 lines (45 loc) · 1.78 KB
/
billscraper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
$chambers = array("senate", "house");
$query = "https://api.propublica.org/congress/v1/115/";
$results = [];
$numbers = [];
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
function getApi ($chamber, $datquery) {
$ch = curl_init();
$fullquery = $datquery . $chamber . "/bills/passed.json";
curl_setopt($ch, CURLOPT_URL, $fullquery);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$headers = array();
$headers[] = "X-Api-Key: ng7dbvmURF4yv9GxugL0Z5y61GWWeL2Kawb5zb4P";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
return $result;
}
// End of generated code
foreach ($chambers as $chamberiteration) {
$json = json_decode(getApi ($chamberiteration, $query), true);
echo '<pre>'; print_r($json); echo '</pre>';
for ($i = 0; $i < count($json['results'][0]['bills']); $i++) {
$location = $json['results'][0]['bills'][$i];
$repeat = False;
if (in_array($location['number'], $numbers)) {
$repeat = True;
}
if ($repeat == False) {
/* INDEXES: 0 - Bill Number 1 - Bill Title 2 - Bill Summary 3 - Latest Major Action 4 - Latest Major Action Date */
$results[] = array($location['number'], $location['title'], $location['summary'], $location['latest_major_action'], $location['latest_major_action_date']);
$numbers[] = $location['number'];
}
}
}
echo '<pre>'; print_r($results); echo '</pre>';
//INDEXING SEGMENT
//This part inputs new bills/bill updates to the local database
?>