Skip to content

Instantly share code, notes, and snippets.

@cdpath
Created December 13, 2015 10:49
Show Gist options
  • Select an option

  • Save cdpath/e0720749372f8b4bf790 to your computer and use it in GitHub Desktop.

Select an option

Save cdpath/e0720749372f8b4bf790 to your computer and use it in GitHub Desktop.
#监控咸鱼商品.sh
#http://www.hi-pda.com/forum/viewthread.php?tid=1735219&extra=page%3D1
#监控商品的具体型号,标题和顶楼内容中符合其中的一项就会提醒:
keyword='newifi'
#价格,低于将提醒
pricelimit=81
#输出到html文件
alertfile=taobao.htm
#邮件SMTP服务器
smtpserver=smtp.163.com
#邮件服务器登录名和密码
[email protected]
mailpassword=password
#发件人邮件地址(有的服务器会验证)
[email protected]
#发件人显示名称(有空格要加双引号)
sendername="your name"
#邮件标题
mailtitle=Alert
#接收邮件地址
[email protected]
#提醒历史记录文件 避免重复提醒
histroyfile=history.txt
#在咸鱼搜索关键词 按发布时间 如果要改成按价格升序 把st_edtime=1改成st_price=0
curl -s --connect-timeout 30 --max-time 60 "https://s.2.taobao.com/list/list.htm?st_edtime=1&q=$keyword&ist=0" | sed -e '1,/item-info/d' | sed -e '1,/pagination/!d' | grep -E 'item-title|item-price|item-description' | tr -d '\n\r' | sed 's/item-title/\n/g' |sed '1d'|sed s/\"\>\<a.*id\=//g | sed s/\<[^\<\>]*\>//g | sed s/\<.*//g | while read line
do
id=${line%\"\>*}
echo -e "\n\e[31m正在处理商品id:$id \e[37m"
#查询threadid是否在历史提醒记录出现过
if [ $(grep -c $id $histroyfile) != 0 ]
then
echo 该帖已经提醒过了,跳过。
else
price=$(echo ${line#*¥} | sed s/\\..*//g)
content=$(echo ${line#*\"\>} | sed s/\¥[0-9]*.[0-9]*//g)
echo 内容:$content
echo 价格:$price
if [ $price -gt $pricelimit ]
then
echo 价格大于限定值:$pricelimit, 跳过。
else
echo 价格小于限定值:$pricelimit
echo 输出到网页
echo -e '<a href=https://2.taobao.com/item.htm?id='$id'>[url]https://2.taobao.com/item.htm?id='[/url]$id'</a><br>'\\n\\r'价格:'$price'元<br>'\\n\\r$content'<br><br>' >>$alertfile
echo 记录到历史记录文件
echo -e "$id\n" >> $histroyfile
echo 邮件提醒
echo echo -e '<a href=https://2.taobao.com/item.htm?id='$id'>[url]https://2.taobao.com/item.htm?id='[/url]$id'</a><br>'\\n\\r'价格:'$price'元<br>'\\n\\r$content | email -no-encoding -html -s $mailtitle -r $smtpserver -m login -u $mailloginname -i $mailpassword -f $mailaddr -n "$sendername" $mailrecipients
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment