Skip to content

Instantly share code, notes, and snippets.

@nonefffds
Last active June 1, 2020 14:55
Show Gist options
  • Save nonefffds/5b42e2051623f3102b302acdef2fb0b0 to your computer and use it in GitHub Desktop.
Save nonefffds/5b42e2051623f3102b302acdef2fb0b0 to your computer and use it in GitHub Desktop.
Push notification if zhaokao.net is updated
#!bin/zsh
# I'll just using zsh as my shell, could be replaced with bash.
cd ~/Downloads/zhaokao # Move to directory of operation
curl -O http://www.zhaokao.net/gzfwlist\?colid\=all # Download the page with cURL, only main page.
mv gzfwlist?colid=all 2.html # Rename
diff 1.html 2.html >> diff.txt # Using built-in diff tool to compare
if [ -s diff.txt ] ; then # [ -s xxx ] meant to validate if the diff.txt is empty(which meant there's no changes), if it's not empty, then return true
awk BEGIN{RS=EOF}'{gsub(/\n/,"");print}' diff.txt >> diff-1.txt # Pre-process the text from diff.txt, delete every "/n", pass it to diff-1.txt
# iOS User with Bark
cat diff-1.txt | xargs -I {} curl https://<PUSH SERVER>/<YOUR APPID>/Update/{} # Get the text from diff-1, using xargs to intent the text to the link that cURL is about to access to
# Android User with Server-chan on Wechat (also work on iOS though)
#cat diff-1.txt | xargs -I {} curl -d'text={}' https://sc.<Server-Chan-URL>.com/<YOUR SCKEY>.send
mv diff.txt /tmp/zhaokao # Move to temp folder instead of directly using rm
mv diff-1.txt /tmp/zhaokao
else
mv diff.txt /tmp/zhaokao # delete useless file
fi
mv 1.html /tmp/zhaokao # The cycle.
mv 2.html 1.html
@nonefffds
Copy link
Author

nonefffds commented May 31, 2020

本 shell 脚本仅用来监控天津市招考资讯网公众服务大厅内栏目,非全站。
本脚本使用推送服务为Bark,安卓用户可以尝试Server-Chan
使用时请将<PUSH SERVER> 改为你使用的推送服务器,并将<YOUR APPID> 改为你 APP 内显示的 App ID。
如果使用 Server-Chan,对应着改就行(然后把上一行注释掉)。
如何定时运行脚本可以参考我的博客,可以尝试部署到 GitHub Actions。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment