微店补货通知大获全胜
前言:好几周前,BIGDONGDONG开始分享他的emby库,账号在微店上获得,但是前几次直播人气太旺,那就只能利用机器的力量在补货的时候通知我了。
20221029: 之前那篇标题里有“监控”违反TOS了,重新换个新文章吧。
方法:BIGDONGDONG的微店《=ProxyAPI(防止反爬虫)《=Python Requests =》Telegram Api(Proxy,通过Works转发API,以达到国内服务器访问的目的)
效果:
实现:重点展示Requests部分,其它的都是前期的项目。其实经过实践,微店并没有禁止同IP的疯狂抓取。
最后贴下code: 小脚本就不传GitHub了😂 注意缩进,
以下发法是:BIGDONGDONG的微店《=Python Requests =》Telegram Api(需要代理访问)。
import requests
import time
import random
from time import gmtime, strftime
import sys
def timenow():
return(strftime("%Y-%m-%d %H:%M:%S", gmtime()))
def TG_Bot_GetMe(bot):
r=requests.get("https://api.telegram.org/bot{}/GetMe".format(str(bot)))
return (r.content.decode())
def TG_Bot_GetUpdates(bot):
r=requests.get("https://api.telegram.org/bot{}/getupdates".format(str(bot)))
return (r.content.decode())
def TG_Bot_SendMessage(bot,chat_id,text):
r=requests.get("https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}".format(str(bot),str(chat_id),str(text)))
return(r.content.decode())
user_agent = {'User-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'}
#https://shop1851686128.v.weidian.com/?userid=1851686128
bot="这里需要改成你自己的Bot ID"
tg_chat_id="通过GetUpdate可以获取chat_id"
errors=0
last_status=""
print(TG_Bot_GetMe(bot))
print(TG_Bot_GetUpdates(bot))
if sys.argv[1]=="1":
print(TG_Bot_SendMessage(bot,tg_chat_id,'【Monitor】 {} \nBIGDONGDONG Emby Monitor is enabled now.'.format(str(timenow()))))
while True:
try:
t=random.randint(10,30)
print("[{}] Sleep For {} seconds".format(timenow(),str(t)))
time.sleep(t)
try:
r = requests.get('https://shop1851686128.v.weidian.com/item.html?itemID=5593028522',headers=user_agent)
except Exception as ex:
print(ex)
if str(r.content).find("sell-out wd-theme__disabled-button1")!=-1:
print("[{}] Sell Out".format(timenow()))
elif str(r.content).find("sold-out wd-theme__disabled-button1")!=-1:
print("[{}] 商品已下架".format(timenow()))
elif str(r.content).find("buy-now wd-theme__button1")!=-1:
print("[{}] Buy Now !!!".format(timenow()))
TG_Bot_SendMessage(bot,tg_chat_id,'【Monitor】 {} \nBIGDONGDONG Emby is avaliable now, buy it here https://shop1851686128.v.weidian.com/?userid=1851686128'.format(str(timenow())))
else:
print(r.content.decode())
if errors>=10:
print(TG_Bot_SendMessage(bot,tg_chat_id,'【Monitor】 {} \nBIGDONGDONG Emby Monitor is disabled now. \nError Info: Reach The Maximum Error Number: {}'.format(str(timenow()),str(errors))))
sys.exit()
else:
errors+=1
print(str(errors)+" Error(s)")
pass
except Exception as ex:
print(TG_Bot_SendMessage(bot,tg_chat_id,'【Monitor】 {} \nBIGDONGDONG Emby Monitor is disabled now. \nError Info: {}'.format(str(timenow()),str(ex))))
20221015补充
下面是Nginx的反代部分的配置
location ^~ / { proxy_pass http://media.xxx.com:8096; proxy_set_header Host "media.xxx.com"; proxy_set_header Referer "http://media.xxx.com:8096/"; proxy_set_header User-Agent $http_user_agent; #proxy_set_header Host $proxy_host; #proxy_set_header X-Real-IP $remote_addr; #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_set_header X-NginX-Proxy true; }
为了让BDD那边不会有什么异常,我还特意了解下Nginx的参数传递,https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
Linux 下利用 Nginx 反向代理
Comments
Post a Comment