Skip to content

Instantly share code, notes, and snippets.

@guilhem
Last active June 24, 2024 10:10
Show Gist options
  • Save guilhem/6abaed0eabb7944bf754911916be5693 to your computer and use it in GitHub Desktop.
Save guilhem/6abaed0eabb7944bf754911916be5693 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Vérifier que le paramètre de prix est fourni
if [ -z "$1" ]; then
echo "Usage: $0 <max_resale_value>"
exit 1
fi
# Définir le prix maximal à partir du premier paramètre
MAX_RESALE_VALUE=$1
# URL de l'API pour récupérer les annonces
API_URL="https://resell.seetickets.com/api/adverts?tickets.product.category=2030&existAvailableTickets=true&status=1&orderby\[nbCartTickets\]=asc&&orderby\[tickets.resaleValue\]=asc&page=1&itemsPerPage=1"
# URL de l'API pour ajouter au panier
CART_URL="https://resell.seetickets.com/solidays2024/cart/add"
# Cookie de session
COOKIE="resale=TOCHANGE"
# Récupérer l'annonce avec resaleValue inférieur au prix maximal et le minPrice
ADVERT_ID=$(curl -s "$API_URL" -H "Cookie: $COOKIE" | jq -r --arg max_resale_value "$MAX_RESALE_VALUE" '.["hydra:member"] | map(select(.tickets[].resaleValue < ($max_resale_value | tonumber))) | min_by(.minPrice) | .id')
# Vérifier si un ID a été trouvé
if [ "$ADVERT_ID" != "null" ]; then
# Créer le payload JSON
JSON_PAYLOAD=$(jq -n --arg id "$ADVERT_ID" '{"id":$id,"captcha":null}')
# Faire le POST pour ajouter au panier et récupérer la réponse
RESPONSE=$(curl -s -X POST "$CART_URL" -H "Content-Type: application/json" -H "Cookie: $COOKIE" -d "$JSON_PAYLOAD")
# Vérifier la réponse pour le succès
SUCCESS=$(echo "$RESPONSE" | jq -r '.success')
if [ "$SUCCESS" != "null" ]; then
MESSAGE=$(echo "$RESPONSE" | jq -r '.success')
echo "Succès: $MESSAGE"
# Émettre une notification
notify-send --urgency=critical "Succès de l'ajout au panier" "$MESSAGE"
paplay /usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga
exit 0
else
echo "Échec de l'ajout au panier. Réponse: $RESPONSE"
# notify-send --urgency=normal "Échec de l'ajout au panier" "$RESPONSE"
# paplay /usr/share/sounds/freedesktop/stereo/bell.oga
exit 1
fi
else
echo "Aucune annonce trouvée avec resaleValue inférieur à $MAX_RESALE_VALUE."
# notify-send --urgency=low "Aucune annonce trouvée avec resaleValue inférieur à $MAX_RESALE_VALUE."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment