commit 4a078daad92a487acc52b5541b72b9c849c7ab4b
parent dde8c418c998635e76cff4247bedc2b1ba3503ba
Author: Johs <[email protected]>
Date: Sun, 11 Jun 2023 22:47:44 +0200
split up fetches
Diffstat:
2 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/Model/Key.php b/Model/Key.php
@@ -1,16 +1,29 @@
<?php
Class Key{
- function myfunction($key){
+ function retrieveData($key){
+ if($key['data'] == ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk') {
+ $key1 = new Key;
+ $key1->retrieveZooData($key);
+ } else if($key['data'] == '?'){
+ $key1 = new Key;
+ $key1->retrieveRBData($key);
+ }
+ }
+
+ function retrieveZooData($key){
if ($key['data'] != ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'){
echo 'no';
} else{
$db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2");
$t = new Lollipop\Template();
$weather_data = [];
- $query = "SELECT temperature, dew_point, wind_speed
+ $query = "SELECT distinct temperature, dew_point, wind_speed, nl.name as city
FROM weather_data wd
JOIN station s ON wd.station_name = s.name
JOIN contract_station cs ON cs.station_name = s.name
+ JOIN nearestlocation nl ON nl.station_name = s.name
+ JOIN country co ON co.country_code = nl.country_code
+ JOIN geolocation geo ON geo.country_code = co.country_code
JOIN contract c ON cs.contract_id = c.contract_id
WHERE c.token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'
LIMIT 5";
@@ -20,17 +33,51 @@ Class Key{
while ($row = $data->fetch_assoc()) {
$wind_chill = windchill($row["temperature"], $row["wind_speed"]);
- $humidity = humid($row["temperature"], $row["dew_point"]);
$weather_data[] = [
'windchill' => $wind_chill,
- 'humidity' => $humidity
+ 'location' => $row['city']
];
}
-
header('Content-Type: application/json');
echo json_encode($weather_data);
}
}
+
+
+
+ function retrieveRBData($key){
+ if ($key['data'] != ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'){
+ echo 'no';
+ } else{
+ $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2");
+ $t = new Lollipop\Template();
+ $weather_data = [];
+ $query = "SELECT distinct temperature, dew_point, nl.name as city
+ FROM weather_data wd
+ JOIN station s ON wd.station_name = s.name
+ JOIN contract_station cs ON cs.station_name = s.name
+ JOIN nearestlocation nl ON nl.station_name = s.name
+ JOIN country co ON co.country_code = nl.country_code
+ JOIN geolocation geo ON geo.country_code = co.country_code
+ JOIN contract c ON cs.contract_id = c.contract_id
+ WHERE c.token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'
+ LIMIT 5";
+ $stmt = mysqli_prepare($db, $query);
+ $stmt->execute();
+ $data = $stmt->get_result();
+
+ while ($row = $data->fetch_assoc()) {
+ $humidity = humid($row["temperature"], $row["dew_point"]);
+ $weather_data[] = [
+ 'humidity' => $humidity,
+ 'location' => $row['city']
+ ];
+ }
+
+ header('Content-Type: application/json');
+ echo json_encode($weather_data);
+ }
+ }
}
function windchill($temp, $wind): float
{
diff --git a/index.php b/index.php
@@ -18,7 +18,7 @@ $router->addRoute(["GET"], "/dashboard", "views/dashboard.html");
$router->addRoute(["GET"], "/hdata", "views/hdata.html");
$router->addRoute(["GET"], "/api/:data", function($vars) {
$key = new Key;
- $key->myfunction($vars);
+ $key->retrieveData($vars);
});
$router->addRoute(['GET'], '/css/dashboard.css', "css/dashboard.css");
$router->route();
\ No newline at end of file