Compare commits

...

2 commits

3 changed files with 43 additions and 0 deletions

View file

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

View file

@ -26,6 +26,18 @@ case "$host" in
mv "$tmpfile" "$filename" 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."; echo "Invalid tracking URL.";
exit -1; exit -1;

View file

@ -77,6 +77,8 @@ complete_reminder() {
rmdir "$tmpdir" rmdir "$tmpdir"
} }
[ -z "$( ls -A "$PACKAGES_DIR/" )" ] && exit # No packages to check!
for package_file in "$PACKAGES_DIR"/*.json; do for package_file in "$PACKAGES_DIR"/*.json; do
echo "$package_file" echo "$package_file"
tracker_type=$(jq -r '.tracker' "$package_file") tracker_type=$(jq -r '.tracker' "$package_file")
@ -113,6 +115,34 @@ for package_file in "$PACKAGES_DIR"/*.json; do
fi fi
done < <(echo "$track_data" | jq -r '.Expedition.Evenements[].Libelle') 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 esac
sleep 1 # Avoid overloading the servers or triggering some rate limiting! sleep 1 # Avoid overloading the servers or triggering some rate limiting!