« Api gouv » : différence entre les versions

Aucun résumé des modifications
 
(29 versions intermédiaires par le même utilisateur non affichées)
Ligne 15 : Ligne 15 :
*[https://doc.data.gouv.fr/api/reference/ doc data gouv api]
*[https://doc.data.gouv.fr/api/reference/ doc data gouv api]
[[category:Divers]] [[category:api]]
[[category:Divers]] [[category:api]]
=== calendrier.api.gouv.fr ===
Jours fériés
<syntaxhighlight lang="bash" copy>
curl -s 'GET' 'https://calendrier.api.gouv.fr/jours-feries/metropole/2027.json'  -H 'accept: application/json' | jq
</syntaxhighlight>
=== apicarto.ign.fr ===
Cadastre
<syntaxhighlight lang="bash" copy>
curl -s 'https://apicarto.ign.fr/api/cadastre/commune?code_insee=02211' | jq
</syntaxhighlight>
<syntaxhighlight lang="bash" copy>
code postaux
curl -s 'https://apicarto.ign.fr/api/codes-postaux/communes/02290' | jq
</syntaxhighlight>


=== adresse.data.gouv.fr ===
=== adresse.data.gouv.fr ===


{{#ifanon:
{{#ifanon:  
|
|  
==== Démo Requete 0 ====
==== Démo Requete 0 ====
<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
curl -s "https://api-adresse.data.gouv.fr/search/?q=8+rue+du+chateau&city=conde+sur+suippe&postcode=02190&autocomplete=0" | jq '.features[0].geometry.coordinates'
curl -s "https://api-adresse.data.gouv.fr/search/?q=8+rue+du+chateau&city=conde+sur+suippe&postcode=02190&autocomplete=0" | jq '.features[0].geometry.coordinates'
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="json">
<syntaxhighlight lang="json">
[
[
Ligne 30 : Ligne 48 :
]
]
</syntaxhighlight>
</syntaxhighlight>
test google maps:   <br />
 
test google maps: <br />
[https://www.google.fr/maps/place/49.417098,3.951548 google.fr/maps/place/49.417098,3.951548]
[https://www.google.fr/maps/place/49.417098,3.951548 google.fr/maps/place/49.417098,3.951548]


----


----
<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
curl -s "https://api-adresse.data.gouv.fr/reverse/?lon=3.951548&lat=49.417098" | jq '.features[0]'
curl -s "https://api-adresse.data.gouv.fr/reverse/?lon=3.951548&lat=49.417098" | jq '.features[0]'
</syntaxhighlight>
</syntaxhighlight>
}}
}}


==== Démo Requete 1 ====
==== Démo Requete 1 ====
Ligne 226 : Ligne 245 :


=== data.education.gouv.fr ===
=== data.education.gouv.fr ===
*[https://data.education.gouv.fr/pages/accueil/ data.education.gouv.fr]
*[https://data.education.gouv.fr/explore/dataset/fr-en-annuaire-education/api/ education api]
Obtenir les infos des établissements scolaires:
Obtenir les infos des établissements scolaires:
<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
Ligne 282 : Ligne 306 :
# Encodage URL
# Encodage URL
encoded_commune=$(echo "$commune" | sed 's/ /%20/g')
encoded_commune=$(echo "$commune" | sed 's/ /%20/g')
where_clause="nom_commune%20like%20%27%25${encoded_commune}%25%27"
#where_clause="nom_commune%20%3D%20%22${encoded_commune}%22%20" #strictement égale
where_clause="nom_commune%20like%20%27${encoded_commune}%27" # like 'paris'
#where_clause="nom_commune%20like%20%27%25${encoded_commune}%25%27" # like '%paris%'


[ -n "$type_etablissement" ] && {
[ -n "$type_etablissement" ] && {
Ligne 290 : Ligne 316 :


# Construction de la requête API
# Construction de la requête API
api_url="https://data.education.gouv.fr/api/explore/v2.1/catalog/datasets/fr-en-annuaire-education/records?where=${where_clause}&limit=${limit}&offset=${offset}"
api_url="https://data.education.gouv.fr/api/explore/v2.1/catalog/datasets/fr-en-annuaire-education/records?&order_by=identifiant_de_l_etablissement&where=${where_clause}&limit=${limit}&offset=${offset}"


# Affichage des paramètres de recherche
# Affichage des paramètres de recherche
echo "Recherche des établissements à '$commune'" >&2
echo "Recherche des établissements à '$commune'" >&2
[ -n "$type_etablissement" ] && echo "Filtre : type '$type_etablissement'" >&2
[ -n "$type_etablissement" ] && echo "Filtre : type '$type_etablissement'" >&2
[ "$output_mode" = "more" ] && echo "Affichage des champs de contact" >&2
[ "$output_mode" = "more" ] && echo "Affichage des champs de contact" >&2
[ "$output_mode" = "all" ] && echo "Affichage de tous les champs disponibles" >&2
[ "$output_mode" = "all" ] && echo "Affichage de tous les champs disponibles" >&2
[ "$offset" -gt 0 ] && echo "Décalage des résultats : $offset" >&2
[ "$offset" -gt 0 ] && echo "Décalage des résultats : $offset" >&2
[ "$limit" -ne 100 ] && echo "Nombre de résultats par page : $limit" >&2
[ "$limit" -ne 100 ] && echo "Nombre de résultats par page : $limit" >&2
echo "" >&2
echo "" >&2


Ligne 311 : Ligne 337 :
         "\($offset + .key + 1)|\(.value.nom_etablissement)|\(.value.type_etablissement)|\(.value.adresse_1)|\(.value.position.lat),\(.value.position.lon)"' | \
         "\($offset + .key + 1)|\(.value.nom_etablissement)|\(.value.type_etablissement)|\(.value.adresse_1)|\(.value.position.lat),\(.value.position.lon)"' | \
         while IFS='|' read -r num etablissement type adresse coord; do
         while IFS='|' read -r num etablissement type adresse coord; do
             printf "%3d | %-30s | %-15s | %-25s | %s\n" \
             printf "%3d | %-30s | %-15s | %-25s | %s\n" \
                   "$num" \
                   "$num" \
                   "$(echo "$etablissement" | cut -c -30)" \
                   "$(echo "$etablissement" | cut -c -30)" \
Ligne 332 : Ligne 358 :
             mail: .value.mail,
             mail: .value.mail,
             web: .value.web
             web: .value.web
         } | with_entries(select(.value != null)))
         } | with_entries(select(.value != null)))
         '
         '
         ;;
         ;;
Ligne 342 : Ligne 368 :
             .value | del(.datasetid, .recordid, .record_timestamp, .geometry) |  
             .value | del(.datasetid, .recordid, .record_timestamp, .geometry) |  
             . + {numero: ($offset + .key + 1)} |
             . + {numero: ($offset + .key + 1)} |
             with_entries(select(.value != null))
             with_entries(select(.value != null))
         )
         )
         '
         '
Ligne 353 : Ligne 379 :
echo "Recherche terminée." >&2
echo "Recherche terminée." >&2
</syntaxhighlight>
</syntaxhighlight>


==== Exemple ====
==== Exemple ====
Ligne 392 : Ligne 419 :




Obtenir les infos d'un établissement précis (si 11ème de la liste)<br />
Obtenir les infos d'un établissement précis (11ème de la liste)<br />
ex:  
ex:  
<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
./ecole.sh -c Reims -t lycee -o 10 -l 1 -f all
./ecole.sh -c Reims -t lycee -o 10 -l 1 -f all
</syntaxhighlight>
</syntaxhighlight>
Résultat
ou
<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
./ecole.sh -c Reims -t lycee -o 10 -l 1 -f more
./ecole.sh -c Reims -t lycee -o 10 -l 1 -f more
</syntaxhighlight>
<pre>
Résultat:
Recherche des établissements à 'Reims'
Recherche des établissements à 'Reims'
Filtre : type 'lycee'
Filtre : type 'lycee'
Ligne 405 : Ligne 435 :
Décalage des résultats : 10
Décalage des résultats : 10
Nombre de résultats par page : 1
Nombre de résultats par page : 1
</syntaxhighlight>
</pre>
<syntaxhighlight lang="json" copy>
<syntaxhighlight lang="json" copy>


Ligne 424 : Ligne 454 :
]
]
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="bash">
<pre>
Nombre de résultats affichés: 1
Nombre de résultats affichés: 1
Prochain offset possible: 11
Prochain offset possible: 11
Recherche terminée.
Recherche terminée.
</pre>






[[category:Divers]] [[category:api]]
[[category:Divers]] [[category:api]]