Added support for Shop2Shop

This commit is contained in:
Yuki Joou 2024-11-10 17:00:13 +01:00
parent 05de07dfa7
commit 69fa7bb770
3 changed files with 41 additions and 0 deletions

View file

@ -25,3 +25,4 @@ trackers as possible!
## Supported trackers
* MondialRelay (France)
* Chronopost Shop2Shop

View file

@ -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;

View file

@ -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!