Created
October 15, 2013 22:04
-
-
Save noleto/6999373 to your computer and use it in GitHub Desktop.
Un simple script pour requêter l'API JCDecaux et enregistrer les données dans un MongoDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MONGO=/path/install/mongo-db/bin | |
HOME=/path/jcdecaux/stockage | |
#Attention: changer le contrat Toulouse par celui de votre ville | |
status=$(curl -w %{http_code} -s 'https://api.jcdecaux.com/vls/v1/stations?contract=Toulouse&apiKey={cleAPI}' -o $HOME/all_stations.json $1) | |
if [ $status -ne 200 ] | |
then | |
error_detail=$(cat $HOME/all_stations.json) | |
echo "[$(date +"%d-%m-%Y_%T")] [JCDecauxAPI] [ERROR] Message for status '$status': $error_detail" | |
else | |
echo "[$(date +"%d-%m-%Y_%T")] [JCDecauxAPI] [OK]" | |
mongoimport_status=$($MONGO/mongoimport --jsonArray -db velos -c stations --file $HOME/all_stations.json 2>&1) | |
if [[ "$mongoimport_status" == *"ERROR"* ]] | |
then | |
echo "[$(date +"%d-%m-%Y_%T")] [MONGODB] [ERROR] Failed on importing: $mongoimport_status" | |
else | |
echo "[$(date +"%d-%m-%Y_%T")] [MONGODB] [OK] ${mongoimport_status:(${#mongoimport_status} - 20)}" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment