diff --git a/README.md b/README.md index 463e48e..bfa7420 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,4 @@ trackers as possible! ## Supported trackers * MondialRelay (France) +* Chronopost Shop2Shop diff --git a/pack2task-add.sh b/pack2task-add.sh index c2baec9..8553f60 100755 --- a/pack2task-add.sh +++ b/pack2task-add.sh @@ -26,6 +26,18 @@ case "$host" in mv "$tmpfile" "$filename" ;; + "www.chronoshop2shop.fr") + tracking_id=$(trurl "$URL" -g '{fragment}' | cut -d'/' -f3) + + filename="$PACKAGES_DIR"/"s2s-$(date '+%Y%m%dT%H%M%S').json" + echo "{}" > "$filename" + + jq '.tracker = "S2S" | .waitingFor = "delivery"' "$filename" > "$tmpfile" + mv "$tmpfile" "$filename" + jq ".trackerInfo.id = \"$tracking_id\"" "$filename" > "$tmpfile" + mv "$tmpfile" "$filename" + ;; + *) echo "Invalid tracking URL."; exit -1; diff --git a/pack2taskd.sh b/pack2taskd.sh index c5fe8c5..9c22858 100755 --- a/pack2taskd.sh +++ b/pack2taskd.sh @@ -113,6 +113,34 @@ for package_file in "$PACKAGES_DIR"/*.json; do fi done < <(echo "$track_data" | jq -r '.Expedition.Evenements[].Libelle') ;; + + "S2S") + tracking_id=$(jq -r '.trackerInfo.id' "$package_file") + waiting_for=$(jq -r '.waitingFor' "$package_file") + url="https://www.chronoshop2shop.fr/tracking/#/numlt/$tracking_id" + + track_data=$(curl "https://www.chronoshop2shop.fr/tracking-ws-rest/tracking/suivi-colis-s2s?lang=fr&listeNumerosLT=$tracking_id" \ + -H "$UA" -H 'Referer: https://www.chronoshop2shop.fr/tracking/') + + while read event; do + if [ "$waiting_for" = 'delivery' ] && [ "$event" = 'Disponible en relais Pickup' ]; then + reminder_uid=$(uuidgen) + set_reminder "$reminder_uid" "Colis Shop2Shop à aller chercher ($tracking_id)" "$url" '7 day' + # Update the package information file, we're now waiting for pickup + tmpfile=$(mktemp) + jq ".waitingFor = \"pickup\" | .reminderUID = \"$reminder_uid\"" "$package_file" > $tmpfile + mv "$tmpfile" "$package_file" + break + fi + + if [ "$waiting_for" = 'pickup' ] && [ "$event" = 'Retiré par le destinataire' ]; then + uid=$(jq -r '.reminderUID' "$package_file") + complete_reminder $uid + rm $package_file + break + fi + done < <(echo "$track_data" | jq -r '.etapes[].libelle') + ;; esac sleep 1 # Avoid overloading the servers or triggering some rate limiting!