Created
July 30, 2023 03:23
-
-
Save DictXiong/793e72896b1390531c72f2ab46e62b89 to your computer and use it in GitHub Desktop.
THU Electricity Balance
This file contains 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/zsh | |
set -e | |
_USERNAME="<your username at myhome.tsinghua.edu.cn>" | |
_PASSWORD="<your password at myhome.tsinghua.edu.cn>" | |
tmp=$(curl -fsSL http://myhome.tsinghua.edu.cn/web_netweb_user/noLogin.aspx | grep VIEWSTATE) | |
viewstate=$(echo $tmp | head -n 1 | sed 's/.*value="\(.*\)".*/\1/g') | |
viewstategen=$(echo $tmp | tail -n 1 | sed 's/.*value="\(.*\)".*/\1/g') | |
test -n "$viewstate" | |
test -n "$viewstategen" | |
tmp=$(curl -v --location 'http://myhome.tsinghua.edu.cn/web_netweb_user/noLogin.aspx' --form "__VIEWSTATE=\"$viewstate\"" --form "__VIEWSTATEGENERATOR=\"$viewstategen\"" --form "net_Default_LoginCtrl1\$txtUserName=\"$_USERNAME\"" --form "net_Default_LoginCtrl1\$txtPassword=\"$_PASSWORD\"" --form 'net_Default_LoginCtrl1$btnLogin="%B5%C7++%C2%BC"' 2>&1 >/dev/null | grep ASP.NET_SessionId) | |
sess_id=$(echo $tmp | /bin/sed 's/.*SessionId=\(.*\); path.*/\1/g') | |
test -n "$sess_id" | |
tmp=$(curl -fsSL -b "ASP.NET_SessionId=$sess_id" http://myhome.tsinghua.edu.cn/web_Netweb_List/Netweb_Home_electricity_Detail.aspx) | |
raw_time=$(echo $tmp | grep Netweb_Home_electricity_DetailCtrl1_lbltime | sed 's?.*Red">\(.*\)</font.*?\1?g' ) | |
test -n "$raw_time" | |
ts=$(date -d $raw_time +%s)000000000 | |
balance=$(echo $tmp | grep Netweb_Home_electricity_DetailCtrl1_lblele | sed 's?.*Red">\(.*\)</font.*?\1?g' ) | |
test -n "$balance" | |
echo electricity_balance value=$balance $ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updates can be found here.