Last active
January 14, 2022 21:06
-
-
Save kopiro/e099341f789e3093d04df243e483a212 to your computer and use it in GitHub Desktop.
Telia GB Left (XBar)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# <xbar.title>Telia GB Left</xbar.title> | |
# <xbar.version>v1.0</xbar.version> | |
# <xbar.author>Flavio De Stefano</xbar.author> | |
# <xbar.author.github>kopiro</xbar.author.github> | |
# <xbar.var>string(SESSID=""): Session ID</xbar.var> | |
# <xbar.var>string(SUBSCRIPTION_ID=""): Subscription ID; if left blank, the first subscription found is gonna be used</xbar.var> | |
headers='-H "Accept: application/json" -H "X-IOS-Build: 4068" -H "ga-av: 10.10.4" -H "ga-aid: com.teliasonera.selfservice.telia" -H "User-Agent: com.teliasonera.selfservice.telia/10.10.4 (iOS 15.2; Apple)" -H "ga-an: Mitttelia"' | |
if [ -z "$SUBSCRIPTION_ID" ]; then | |
subscriptions=$(/usr/bin/curl -s https://sa.telia.se/se/rs/subscriptions -H "Cookie: STSSESSION=$SESSID" $headers) | |
SUBSCRIPTION_ID=$(echo "$subscriptions" | /usr/local/bin/jq -r ".[0].id") | |
fi | |
usage=$(/usr/bin/curl -s "https://sa.telia.se/se/rs/subscriptions/$SUBSCRIPTION_ID/usage" -H "Cookie: STSSESSION=$SESSID" $headers) | |
bytes_limit=$(echo "$usage" | /usr/local/bin/jq -r ".usagesForCategory[0].limit") | |
gigabytes_limit=$(echo "scale=0; $bytes_limit / 1024 / 1024 / 1024" | bc) | |
bytes_remaining=$(echo "$usage" | /usr/local/bin/jq -r ".usagesForCategory[0].remaining") | |
gigabytes_remaining=$(echo "scale=0; $bytes_remaining / 1024 / 1024 / 1024" | bc) | |
bytes_used=$(echo "$usage" | /usr/local/bin/jq -r ".usagesForCategory[0].used") | |
gigabytes_used=$(echo "scale=0; $bytes_used / 1024 / 1024 / 1024" | bc) | |
echo "${gigabytes_remaining}GB" | |
echo "---" | |
echo "Limit: ${gigabytes_limit}GB" | |
echo "Used: ${gigabytes_used}GB" | |
echo "Remaining: ${gigabytes_remaining}GB" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment