Last active
May 3, 2020 13:19
-
-
Save imdong/3510fa7162e0ef343302351cdd159ef0 to your computer and use it in GitHub Desktop.
著名程序员论坛自动签到
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/bash | |
# | |
# v2ex 自动签到 | |
# 博客: https://www.qs5.org | |
# 作者: ImDong(青石) | |
# | |
# 2020年05月03日21:00:46 | |
# | |
# 使用方法: 将网站登录后的 Cookies 保存到 txt 内,然后修改下面的配置即可 | |
# | |
# crontab: | |
# * * * * * /bin/bash /home/pi/Projects/load_v2ex.sh >> /home/pi/Projects/load_v2ex.log | |
# 请求域名 | |
V2_DOMAIN="https://www.v2ex.com" | |
# Cookies 保存文件 | |
COOKIE_FILE="/home/pi/Projects/v2_cookie.txt" | |
# 登录用户名 | |
V2EX_USERNAME="imdong" | |
# 默认查询频率 | |
sleep_time=5 | |
loop_num=3 | |
# 发送请求 | |
send(){ | |
# result=`cat tmp.html` | |
result=$(/usr/bin/curl -s -L --cookie "${COOKIE_DATA}" "${V2_DOMAIN}${1}") | |
# echo ${result} > /home/pi/Projects/tmp.html | |
# 判断是否已经登录 | |
title=`echo ${result} | /bin/grep -o '<title>\([^<]\+\)</title>'` | |
title=${title:7:${#title}-15} | |
if [ "${title:0-2}" == "登录" ]; then | |
echo "未登录..." | |
exit 127 | |
fi | |
# 是否已签到 | |
tmp_str=`echo ${result} | /bin/grep -o "/mission/daily/redeem?once=[^']\+"` | |
if [ "${#tmp_str}" -gt "10" ]; then | |
send ${tmp_str} | |
echo "签到成功" | |
fi | |
} | |
echo -e "ST: $(date)\t\c" | |
# 检查 cookie | |
if [ ! -f "${COOKIE_FILE}" ]; then | |
echo "请创建cookie.txt文件"; | |
exit 0 | |
fi | |
COOKIE_DATA=`cat ${COOKIE_FILE}` | |
# echo ${COOKIE_DATA} | |
# 初始检查 | |
send "/top/dau" | |
# 判断位置(计算频率) | |
list=`echo ${result} | grep -oP "<h2[^>]+><span[^>]+>([0-9]+)\.<\/span>\s*<a[^>]+>([^<]+)<\/a><\/h2>[^&]+ ([0-9]+)&" | sed "s/<h2[^>]\+><span[^>]\+>\([0-9]\+\)\.<\/span>\s*<a[^>]\+>\([^<]\+\)<\/a><\/h2>[^&]\+ \([0-9]\+\)&$s/\1,\2,\3/g" | tr '\n' '|'`; | |
no1_name=`echo ${list} | cut -d"|" -f 1 | cut -d"," -f 2` | |
no1_num=`echo ${list} | cut -d"|" -f 1 | cut -d"," -f 3` | |
no2_num=`echo ${list} | cut -d"|" -f 2 | cut -d"," -f 3` | |
((gap_num=${no1_num} - ${no2_num})) | |
# echo "${no1_num}, ${no2_num}, ${gap_num}" | |
if [[ ! "${no1_name}" == "${V2EX_USERNAME}" ]] || [[ "${gap_num}" -lt "2000" ]] ;then | |
echo "高频模式, ${no1_name}, ${no1_num} - ${no2_num} = ${gap_num}" | |
sleep_time=1 | |
loop_num=9 | |
elif [[ "${no1_name}" == "${V2EX_USERNAME}" ]] && [[ "${gap_num}" -gt "3000" ]] ;then | |
echo "低频模式, ${no1_name}, ${no1_num} - ${no2_num} = ${gap_num}" | |
sleep_time=0 | |
loop_num=1 | |
else | |
echo "平时模式, ${no1_name}, ${no1_num} - ${no2_num} = ${gap_num}" | |
fi | |
# 检查页面 | |
for ((i=1; i<=${loop_num}; i ++)) | |
do | |
# 检查页面 | |
printf "%02d: " ${i} | |
echo -e "$(date)\t\c" | |
send "/mission/daily" | |
echo -e "${title}\t刷新完毕" | |
/bin/sleep ${sleep_time} | |
done | |
echo -e "EN: $(date)\tExit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment