export city as csv

This commit is contained in:
Tykayn 2025-06-03 13:04:09 +02:00 committed by tykayn
parent c20a77b811
commit 485f1774d0
2 changed files with 46 additions and 1 deletions

View file

@ -357,5 +357,17 @@ final class AdminController extends AbstractController
return $response;
}
#[Route('/admin/export_csv/{zip_code}', name: 'app_admin_export_csv')]
public function export_csv(string $zip_code): Response
{
$stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $zip_code]);
$response = new Response($this->motocultrice->export($zip_code));
$response->headers->set('Content-Type', 'text/csv');
$slug_name = str_replace(' ', '-', $stats->getName());
$response->headers->set('Content-Disposition', 'attachment; filename="osm-commerces-export_' . $zip_code . '_' . $slug_name . '_' . date('Y-m-d_H-i-s') . '.csv"');
return $response;
}
}

View file

@ -61,6 +61,39 @@ class Motocultrice
];
public function export($zone) {
$query = $this->get_export_query($zone);
try {
$response = $this->client->request('GET', 'https://overpass-api.de/api/interpreter', [
'query' => [
'data' => $query
]
]);
return $response->getContent();
} catch (\Exception $e) {
return "Erreur lors de la requête Overpass : " . $e->getMessage();
}
}
public function get_export_query($zone) {
return <<<QUERY
[out:csv(::id,::type,::lat,::lon,name,amenity,shop,office,healthcare,"contact:email",email,"contact:phone",phone,"contact:website",website,image,url,wikidata, opening_hours,"contact:housenumber","addr:housenumber","contact:street","addr:street",note,fixme,harassment_prevention,cuisine,brand,tourism,source,zip_code,"ref:FR:SIRET")];
area["ISO3166-1"="FR"]->.france;
area["postal_code"="{$zone}"](area.france)->.searchArea;
(
nw["amenity"~"^(cafe|bar|restaurant|library|cinema|fast_food|post_office|marketplace|community_centre|theatre|bank|townhall)$"](area.searchArea);
nw["shop"](area.searchArea);
nw["healthcare"](area.searchArea);
nw["office"](area.searchArea);
);
out body;
QUERY;
}
public function get_query_places($zone) {
return <<<QUERY
[out:json][timeout:25];