Initial commit

This commit is contained in:
William Bouzourène 2025-03-04 20:26:33 +01:00
commit ef9f05e031
12 changed files with 3801 additions and 0 deletions

54
public/api/query.php Normal file
View file

@ -0,0 +1,54 @@
<?php declare(strict_types=1);
function getParam(string $name, string $default = ""): string {
if (isset($_GET[$name]) && !empty($_GET[$name])) {
return (string)$_GET[$name];
}
return $default;
}
function getParamInt(string $name, int $default = 0): int {
if (isset($_GET[$name]) && !empty($_GET[$name])) {
return (int)$_GET[$name];
}
return $default;
}
$zip = getParamInt("zip", 0);
$city = getParam("city", "");
$time = time();
$url = "https://service.post.ch/zopa/app/api/addresschecker/v1/zips?limit=9999&noCache={$time}";
if (strlen($city) > 0) {
$url .= "&city={$city}";
}
if ($zip >= 1000 && $zip <= 9999) {
$url .= "&zip={$zip}";
}
$response = file_get_contents($url);
$json = json_decode($response);
$zips = [];
if (isset($json->zips) && !empty($json->zips)) {
foreach ($json->zips as $zip) {
if (!isset($zip->zip) || empty($zip->zip)) {
continue;
}
if (!isset($zip->city27) || empty($zip->city27)) {
continue;
}
$zips[(int)$zip->zip] = $zip->city27;
}
}
header("Content-Type: application/json");
echo json_encode([
"zips" => $zips
], JSON_PRETTY_PRINT);

0
public/assets/.gitkeep Normal file
View file

13
public/index.html Normal file
View file

@ -0,0 +1,13 @@
<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Codes postaux | Suisse</title>
<link rel="stylesheet" href="/assets/main.css">
</head>
<body>
<div id="app"></div>
<script src="/assets/main.js" type="module"></script>
</body>
</html>