api.php (2024B) download
1<?php
2
3function storeZooData($dataArray): void{
4 if ($dataArray != '') {
5 $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "panda");
6 $query = "INSERT IGNORE INTO retrieve_zoos (data_id, city, wind_chill, date, country) VALUES (?, ?, ?, ?, ?)";
7 $stmt = mysqli_prepare($db, $query);
8
9 foreach ($dataArray as $data) {
10 $data_id = $data->data_id;
11 $city = $data->city;
12 $windchill = $data->windchill;
13 $date = $data->date;
14 $country = $data->country;
15
16 $stmt->bind_param("isdss", $data_id, $city, $windchill, $date, $country);
17 $stmt->execute();
18 }
19
20 $stmt->close();
21 $db->close();
22 }
23}
24
25function storeFacData($dataArray): void{
26 if ($dataArray != '') {
27 $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "panda");
28 $query = "INSERT IGNORE INTO retrieve_facilities (data_id, city, date_time, humidity) VALUES (?, ?, ?, ?)";
29 $stmt = mysqli_prepare($db, $query);
30
31 foreach ($dataArray as $data) {
32 $data_id = $data->data_id;
33 $city = $data->city;
34 $humidity = $data->humidity;
35 $date_time = $data->date_time;
36
37 $stmt->bind_param("issd", $data_id, $city, $date_time, $humidity);
38 $stmt->execute();
39 }
40
41 $stmt->close();
42 $db->close();
43 }
44}
45
46function get_windchill(){
47 $token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk';
48 $since = $vars['since'] ?? "''";
49 $url = 'http://86.92.67.21/api/windchill/' . $since;
50 $connect = new Model\Connect($url, $token);
51 $response = $connect->connect();
52 storeZooData($response);
53}
54function get_graph(){
55 $token = 'ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684';
56 $since = $vars['since'] ?? "''";
57 $url = 'http://86.92.67.21/api/graph/' . $since;
58 $connect = new Model\Connect($url, $token);
59 $response = $connect->connect();
60 storeFacData($response);
61}