From 7231708b5e6c1d58fb109c2b53e8ccc02a44bd3e Mon Sep 17 00:00:00 2001 From: roiding Date: Mon, 21 Feb 2022 13:09:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=85=A8=E4=BD=93docker=20=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E7=9A=84linux=E5=9F=BA=E7=A1=80=E8=BF=98=E6=98=AF?= =?UTF-8?q?=E5=A4=AA=E5=B7=AE=E4=BA=86=EF=BC=8C=E5=87=A0=E8=A1=8Clinux?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8A=98=E8=85=BE=E4=BA=86=E4=B8=80=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 +-- jiankong.py | 40 ++++++++++++++++++------------ shuafen.py | 71 +++++++++++++++++++++++++++++++---------------------- start.sh | 23 ++++++++++++++--- 4 files changed, 87 insertions(+), 51 deletions(-) diff --git a/Dockerfile b/Dockerfile index af0a3a7..1a2239a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,6 @@ COPY jiankong.py jiankong.py COPY start.sh start.sh -RUN pip install requests && chmod +x start.sh && mkdir -p /usr/yili-carebaby-game/logs +RUN pip install requests &&chmod +x start.sh&& mkdir -p /usr/yili-carebaby-game/logs -ENTRYPOINT /usr/yili-carebaby-game/start.sh \ No newline at end of file +CMD ["/usr/yili-carebaby-game/start.sh"] \ No newline at end of file diff --git a/jiankong.py b/jiankong.py index 667cb2e..5c48b60 100644 --- a/jiankong.py +++ b/jiankong.py @@ -1,43 +1,51 @@ -from itertools import count -import requests +import logging +import os import re -import time import sys +import time +import requests import urllib3 + # 关闭安全请求警告 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) +logging.basicConfig(level=logging.INFO, + filename=os.path.join(os.getcwd(), 'log.txt'), + format='%(asctime)s - %(levelname)s: %(message)s') + def checkCount(token): - i=0 + i = 0 while(True): - i=i+1 + i = i+1 # 请求url,解析变量值 response = requests.get( "https://www.yilibabyclub.com/malldetail.aspx?dataid=300406&giftid=8075&code=202206002", verify=False, proxies={'https': None}) count_str = re.findall("var giftcount = (\d+);", response.text) count_int = int(count_str[0]) - print("执行第%s次,当前库存%s" %(i,count_int)) + + logging.info("执行第%s次,当前库存%s", i, count_int) + if(count_int != 0): # 执行通知 - data = {"title": "有货了", "desp":"赶快去抢啊,快点的"} - url="https://sctapi.ftqq.com/"+token+".send" - data=requests.post( - url, params=data,proxies={'https': None}) + data = {"title": "所选商品有货了", "desp": "所选设备已有,赶快去抢啊"} + url = "https://sctapi.ftqq.com/"+token+".send" + data = requests.post( + url, params=data, proxies={'https': None}) break time.sleep(30) if __name__ == '__main__': # 输入了token值 - if len(sys.argv)==2: - print("开始执行库存监控") + if len(sys.argv) == 2: + logging.info("开始执行库存监控") checkCount(sys.argv[1]) - elif len(sys.argv)==1: - sendKey=input("请输入你的Server酱SendKey值:") - print("开始执行库存监控") + elif len(sys.argv) == 1: + sendKey = input("请输入你的Server酱SendKey值:") + logging.info("开始执行库存监控") checkCount(sendKey) else: - print("本程序只支持1个参数,请勿多输") + logging.info("本程序只支持1个参数,请勿多输") diff --git a/shuafen.py b/shuafen.py index 4c1d6c6..7edd150 100644 --- a/shuafen.py +++ b/shuafen.py @@ -1,39 +1,48 @@ -import requests -import time +import logging +import os import random import sys +import time +import requests import urllib3 -#关闭安全请求警告 + +# 关闭安全请求警告 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) +logging.basicConfig(level=logging.INFO, + filename=os.path.join(os.getcwd(), 'logs/shuafen.log'), + format='%(asctime)s - %(levelname)s: %(message)s') + game_level = 1 -curr_score=0 -#有4000个钻石就停止 +curr_score = 0 +# 有4000个钻石就停止 + + def start_game(authorization): - global game_level,curr_score + global game_level, curr_score while(curr_score <= 4000): # 请求头 header = {'Host': 'babyclub.msxapi.digitalyili.com', 'Connection': 'keep-alive', - 'Accept': 'application/json, text/plain, */*', - # 修改此处为自己的微信auth - 'Authorization': 'XXXX', - 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat', - 'Content-Type': 'application/json;charset=UTF-8', - 'Sec-Fetch-Site': 'same-site', - 'Sec-Fetch-Mode': 'cors', - 'Sec-Fetch-Dest': 'empty', - 'Referer': 'https://babyclub.msx.digitalyili.com//', - 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'en-us,en'} - header['Authorization']=authorization + 'Accept': 'application/json, text/plain, */*', + # 修改此处为自己的微信auth + 'Authorization': 'XXXX', + 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat', + 'Content-Type': 'application/json;charset=UTF-8', + 'Sec-Fetch-Site': 'same-site', + 'Sec-Fetch-Mode': 'cors', + 'Sec-Fetch-Dest': 'empty', + 'Referer': 'https://babyclub.msx.digitalyili.com//', + 'Accept-Encoding': 'gzip, deflate, br', + 'Accept-Language': 'en-us,en'} + header['Authorization'] = authorization response = requests.get( "https://babyclub.msxapi.digitalyili.com/api/v1/game/play_auth", headers=header, verify=False) # 提交分数token score_token = response.json()['data']['score_token'] game_level = response.json()['data']['game_level'] - print("当前进度:%s" %(game_level)) + logging.info("当前进度:%s",game_level) # 暂停60s 与游戏时间保持一致 防止被查 time.sleep(60) request_data = { @@ -46,20 +55,22 @@ def start_game(authorization): request_data['auth_token'] = score_token request_data['game_level'] = game_level+1 request_data['score'] = 5*random.randint(19, 28) - score_response=requests.post("https://babyclub.msxapi.digitalyili.com/api/v1/game/submit_score", - json=request_data, headers=header, verify=False) - print("%s:成绩已提交:分数为%s" %(game_level,request_data['score'])) - curr_score=score_response.json()['data']['history_total_score'] - print("当前共赚取%s钻石" %(curr_score)) + score_response = requests.post("https://babyclub.msxapi.digitalyili.com/api/v1/game/submit_score", + json=request_data, headers=header, verify=False) + logging.info("%s:成绩已提交:分数为%s",game_level,request_data['score']) + curr_score = score_response.json()['data']['history_total_score'] + logging.info("当前共赚取%s钻石",curr_score) time.sleep(2) + + if __name__ == '__main__': # 输入了auth值 - if len(sys.argv)==2: - print("开始执行钻石获取") + if len(sys.argv) == 2: + logging.info("开始执行钻石获取") start_game(sys.argv[1]) - elif len(sys.argv)==1: - authorization=input("请输入你的微信登录Authorization值:") - print("开始执行钻石获取") + elif len(sys.argv) == 1: + authorization = input("请输入你的微信登录Authorization值:") + logging.info("开始执行钻石获取") start_game(authorization) else: - print("本程序只支持1个参数,请勿多输") + logging.info("本程序只支持1个参数,请勿多输") diff --git a/start.sh b/start.sh index 2c49492..9638fc6 100644 --- a/start.sh +++ b/start.sh @@ -1,20 +1,37 @@ +#!/bin/sh + +trap closePython SIGTERM + + if [ $AUTHORIZATION ] then - python ./shuafen.py $AUTHORIZATION &>./logs/shuafen.log & + python ./shuafen.py $AUTHORIZATION &>>./logs/runtime.log & pid1=$! fi echo "pid1:${pid1}" if [ $SENDKEY ] then - python ./jiankong.py $SENDKEY &>./logs/jiankong.log & + python ./jiankong.py $SENDKEY &>>./logs/runtime.log & pid2=$! fi echo "pid2:${pid2}" +closePython(){ + if [ -n "${pid1}" -o -d "/proc/${pid1}" ]] + then + kill ${pid1} + fi + if [ -n "${pid2}" -o -d "/proc/${pid2}" ]] + then + kill ${pid2} + fi +} + while true -do +do + if [ -n "${pid1}" -o -d "/proc/${pid1}" ] || [ -n "${pid2}" -o -d "/proc/${pid2}" ] then sleep 1s