diff --git a/contrib/ai-simulator/script-scrap-weeklynet.sh b/contrib/ai-simulator/script-scrap-weeklynet.sh index fed57d44a549fdf4e9ab94598fd697a78912c2c6..1856695069b39387f241070abbb75a6e6446273e 100755 --- a/contrib/ai-simulator/script-scrap-weeklynet.sh +++ b/contrib/ai-simulator/script-scrap-weeklynet.sh @@ -16,6 +16,26 @@ l=$1 batch_size=10 +today=$(date +%Y-%m-%d) + +# Get the numeric representation of the current day of the week (0 for Sunday, 6 for Saturday) +day_of_week=$(date +%u) + +# Calculate how many days ago was the last Wednesday +# Bash considers Sunday as the start of the week (i.e., day 0) +# We need to get to day 3 (Wednesday) of the week +if [ "$day_of_week" -gt 3 ]; then + # If today is after Wednesday, subtract the difference from today + days_to_subtract=$((day_of_week - 3)) +else + # If today is before Wednesday, subtract the difference from the previous week + days_to_subtract=$((day_of_week + 4)) +fi + +last_wednesday=$(date -d "$today - $days_to_subtract days" +%Y-%m-%d) + +endpoint="https://rpc.weeklynet-${last_wednesday}.teztnets.com" + for ((i = 0; i <= l; i += batch_size)); do echo "Launching data request for batch starting with cycle: $i" @@ -23,21 +43,21 @@ for ((i = 0; i <= l; i += batch_size)); do for ((n = i; n < $((i + batch_size)) && n <= l; n++)); do block=$((128 * (1 + n))) - (curl -s https://rpc.weeklynet-2024-03-27.teztnets.com/chains/main/blocks/$block/context/total_supply > "/tmp/ai-sim-supply/$n.txt" &) + (curl -s "$endpoint"/chains/main/blocks/$block/context/total_supply > "/tmp/ai-sim-supply/$n.txt" &) - (curl -s https://rpc.weeklynet-2024-03-27.teztnets.com/chains/main/blocks/$block/context/total_frozen_stake > "/tmp/ai-sim-frozen/$n.txt" &) + (curl -s "$endpoint"/chains/main/blocks/$block/context/total_frozen_stake > "/tmp/ai-sim-frozen/$n.txt" &) ( - public_keys=$(curl -s https://rpc.weeklynet-2024-03-27.teztnets.com/chains/main/blocks/$block/context/delegates) + public_keys=$(curl -s "$endpoint"/chains/main/blocks/$block/context/delegates) public_keys=$(echo "$public_keys" | tr -d '[]"') public_keys=$(echo "$public_keys" | tr ',' ' ') sum=0 for pkh in $public_keys; do - balance1=$(curl -s https://rpc.weeklynet-2024-03-27.teztnets.com/chains/main/blocks/$block/context/delegates/"$pkh"/delegated_balance | tr -d '"') + balance1=$(curl -s "$endpoint"/chains/main/blocks/$block/context/delegates/"$pkh"/delegated_balance | tr -d '"') - balance2=$(curl -s https://rpc.weeklynet-2024-03-27.teztnets.com/chains/main/blocks/$block/context/delegates/"$pkh"/full_balance | tr -d '"') + balance2=$(curl -s "$endpoint"/chains/main/blocks/$block/context/delegates/"$pkh"/full_balance | tr -d '"') balance=$((balance1 + balance2))