-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
52 lines (39 loc) · 1.48 KB
/
index.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
47
48
49
50
51
52
<?php
// Run this file to put *all* the data up every month
// Socrata Engine
require_once("socrata.php");
// Your credentials
$root_url = '';
$app_token = '';
$database_id = '';
$username = '';
$password = '';
$response = NULL;
$google_key = '';
// Create a new authenticated client
$socrata = new Socrata($root_url, $app_token, $username, $password);
// Get the raw data from the source
$raw_data = file_get_contents('https://maps.googleapis.com/maps/api/place/textsearch/json?query=bike%20shops+in+Bath%20and%20North%20East%20Somerset&key=' . $google_key);
// Decode the data
$decoded_data = json_decode($raw_data, true);
// Create a blank array ready for the data
$formatted_rows = array();
// Loop through the decoded data
foreach ($decoded_data['results'] as $data_row) {
$formatted_row = array(
"place_id" => $data_row['place_id'],
"place_name" => $data_row['name'],
"address" => $data_row['formatted_address'],
"rating" => $data_row['rating'],
"location" => '(' . $data_row['geometry']['location']['lat'] . ',' . $data_row['geometry']['location']['lng'] . ')'
);
// Add the data to the array
array_push($formatted_rows, $formatted_row);
// Output something to the browser
echo 'Getting data for ' . $data_row['name'] . '<br />';
}
// Re-encode the array as JSON and post it to Socrata
$response = $socrata->post('/resource/' . $database_id, json_encode($formatted_rows));
// Output some info to the browser
echo '<br />Done!<br />';
?>