-
-
Save marco79cgn/1184e77b39fdf7ba510ac8650afe0674 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
partNo=$1 | |
storeId=$2 | |
notifyUrl=https://ntfy.sh/$3 | |
FILE=$4/${partNo/\//-}-$storeId | |
if [ ! -f "$FILE" ]; then | |
echo "$FILE does not exist." | |
echo -n "1" > $FILE | |
fi | |
productName="" | |
function curlItem { | |
apiResult=$(/usr/bin/curl -s "https://www.apple.com/de/shop/fulfillment-messages?store=${storeId}&little=false&parts.0=${partNo}&purchaseOption=fullPrice&mts.0=regular&mts.1=sticky&fts=true") | |
productName=$(echo -n ${apiResult} | jq -r ".body.content.pickupMessage.stores[0].partsAvailability.\"${partNo}\".messageTypes.regular.storePickupProductTitle") | |
storeAvailability=$(echo -n ${apiResult} | jq -r ".body.content.pickupMessage.stores[0].partsAvailability.\"${partNo}\".pickupDisplay" | grep -i -w "available" | wc -l) | |
printf "Store ${storeId}: ${storeAvailability}" | |
if [ "$storeAvailability" -eq "1" ]; then | |
previousState=$(<$FILE) | |
if [[ "$previousState" == 0 ]]; then | |
sendPush | |
echo -n "1" > $FILE | |
exit | |
fi | |
else | |
echo -n "0" > $FILE | |
fi | |
} | |
function sendPush { | |
result=$(/usr/bin/curl -s -X POST -H "Title: Apple Store" -H "Click: https://store.apple.com/de/xc/product/$partNo" -H "Tags: apple" -d "${productName} ist jetzt verfügbar! (Tap to order)" $notifyUrl) | |
} | |
responsedata=$(curlItem) | |
echo $responsedata |
@Manu8D
Ach spannend, Danke für‘s Feedback und natürlich Glückwunsch zum Kauf.
Ich hatte mich kürzlich erst gefragt, wie mein 2 Jahre alter Code eigentlich funktionieren kann aus genau dem Grund, den du genannt hast. Aber bei mir funktioniert er tatsächlich so, weil die Anführungszeichen explizit Teil der Ausgabe und des greps sind. Daher matcht „available“
nicht auf „unavailable“
. Anders wäre es, wenn ich jq -r
(raw) machen würde, denn dann werden die Anführungszeichen unterdrückt. Ich teste nochmal mit deiner Lösung und passe dann das Skript an, wenn‘s klappt.
//EDIT:
Skript ist angepasst!
Update 24.09.2023
Das Skript ist jetzt komplett universell benutzbar und muss nicht mehr editiert werden. Beim Aufruf müssen die benötigten 4 Parameter lediglich mitgegeben werden: partNo storeId notifyTopic tempFolder
Zum Beispiel für das iPhone 15 Pro Max 256 GB Titan Blau im Apple Store Köln Schildergasse:
./apple-availability-check.sh "MU7A3ZD/A" "R559" "my-secret-apple-alerts-395920" "/Users/marco/dev/temp"
Hi, wie bekommt man die StoreID heraus?
Gibt in Berlin z.B. einen neuen Store.
@obiwan007
Rosenthaler Straße 44
10178 Berlin
storeNumber: R443
Vielen Dank für das Script! Ich habe damit eben erfolgreich mein iPhone zur Abholung für morgen bestellt. Eine kleine Anmerkung: Bei mir hat das Script auf dem Raspberry Pi dauerhaft angeschlagen, weil "grep -i "available" auch "unavailable" gefunden hat. Mit "grep -i -w "available" hat es dann aber funktioniert.