-
Notifications
You must be signed in to change notification settings - Fork 0
/
grab_counts.php
30 lines (24 loc) · 1.1 KB
/
grab_counts.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
<?php
//This should be run on cron.
include_once('config.php');
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$timeNow = gmdate("Y-m-d H:i:s");
$saved = 0;
for( $categoryId = 0; $categoryId <= 12; $categoryId++ ){
foreach( ['yes','limited','no','unknown'] as $wheelchair_filter ){
$categoriesUrlFragment = ($categoryId >= 1) ? "categories/".$categoryId."/" : "";
$json = json_decode(file_get_contents("https://wheelmap.org/api/".$categoriesUrlFragment."nodes?api_key=$wheelmap_api_key&bbox=-2.413769,51.363902,-2.310473,51.415048&wheelchair=$wheelchair_filter"), true);
$item_count = $json['meta']['item_count_total'];
$success = $mysqli->query("INSERT INTO venue_counts (`category`,`wheelchair`,`time`,`count`) VALUES ('$categoryId','$wheelchair_filter','$timeNow','$item_count')");
if( !$success ){
die( $mysqli->error );
}
else{
$saved++;
}
}
}
echo "Saved $saved rows to DB.";