# !/bin/env python3# -*- coding: utf-8 -*"""link: https://raw.githubusercontent.com/yml2213/Python/master/sbr/sbr.pynew Env("苏泊尔")Name: 苏泊尔 小程序 种大米,换实物Author: ymlDate: 2022年7月12日cron: 19 7,12 * * * sbr.py7.13 完成 签到, 偷大米, 浏览菜谱 任务================== 青龙--配置文件 ==================变量格式: export sbr_data=" token & cookie @ token & cookie " ,多账号用 换行 或 @ 分割token 抓 https://growrice.supor.com/rice/backend/public/index.php/api/login/auto-login 的包 , url 后面就是tokencookie 抓 https://growrice.supor.com/rice/backend/public/index.php/api/users/get-user-info 的包 , header 中有cookie"""# ================================= 以下代码不懂不要随便乱动 ====================================try:import requestsimport jsonimport sysimport osimport reimport timeimport randomexcept Exception as e:print(e)requests.packages.urllib3.disable_warnings()# --------------------------------------------------------------------------------------------Script_Name = "苏泊尔"Name_Pinyin = "sbr"Script_Change = "完成 签到, 偷大米, 浏览菜谱 任务"Script_Version = "0.0.2"# --------------------------------------------------------------------------------------------def start():global _ck_state_ck_state = 1for inx, data in enumerate(ckArr):msg("=============== 开始第" + str(inx + 1) + "个账号 ===============")ck = data.split("&")sbr = Script(ck[0], ck[1])sbr.login()sbr.user_info("用户信息")if _ck_state:sbr.sign_info("签到信息")sbr.task_list("任务列表")sbr.get_index_info("获取可收取大米信息")class Script:def __init__(self, token, cookie):self.token = tokenself.cookie = cookie# noinspection PyMethodMayBeStaticdef url(self, name):url = f"https://growrice.supor.com/rice/backend/public/index.php/api/{name}"return urldef headers(self):headers = {'Host': 'growrice.supor.com','Cookie': self.cookie,'content-type': 'application/x-www-form-urlencoded'}return headersdef login(self): # 登录刷新url_login = f"https://growrice.supor.com/rice/backend/public/index.php/api/login/auto-login?token={self.token}"try:requests.get(url=url_login, headers=self.headers(), verify=False)except Exception as err:print(err)def user_info(self, name): # 用户信息global _ck_statetry:response = requests.get(url=self.url("users/get-user-info"), headers=self.headers(), verify=False)result = response.json()# print(result)if result['code'] == 1:msg(f"{name}: {result['msg']}, 欢迎 {result['data']['nickname']}")time.sleep(2)elif result['code'] == 0:msg(f"{name}: {result['msg']}")_ck_state = 0return _ck_stateelse:msg(f"{name}: 失败, 请稍后再试!")print(result)_ck_state = 0return _ck_stateexcept Exception as err:print(err)def sign_info(self, name): # 签到信息查询try:response = requests.get(url=self.url("signIn/sign-list"), headers=self.headers(), verify=False)result = response.json()# print(result)if not result['data']['is_sign']:msg(f"{name}: 未签到 ,去签到喽!")self.do_sign("签到")elif result['data']['is_sign']:msg(f"{name}: 已签到, 明天再来吧!")else:msg(f"{name}: 失败, 请稍后再试!")print(result)except Exception as err:print(err)def do_sign(self, name): # 执行签到try:payload = "https://growrice.supor.com/rice/backend/public/index.php/api/signIn/sign"response = requests.post(url=self.url("signIn/sign"), headers=self.headers(), data=payload, verify=False)result = response.json()if result['code'] == 1:msg(f"{name}: {result['msg']}, 获得 {result['data']['get_rice_num']} 大米")time.sleep(3)self.browse_recipes("浏览菜谱")elif result['code'] == 0:msg(f"{name}: {result['msg']}")else:msg(f"{name}: 失败, 请稍后再试!")print(result)except Exception as err:print(err)def task_list(self, name): # 任务列表try:response = requests.get(url=self.url("task/index"), headers=self.headers(), verify=False)result = response.json()# print(result)if result['code'] == 1:print(f"{name}: {result['msg']}")task_list = result['data']for task in task_list:if task['id'] != 8:_id, name, is_finish = task['id'], task['name'], task['is_finish']if _id == 6 and is_finish is False:self.get_rice("偷大米")elif _id == 6 and is_finish is True:msg("今天无法偷大米了, 明天再来吧!")passelif result['code'] == 0:msg(f"{name}: {result['msg']}")else:msg(f"{name}: 失败, 请稍后再试!")print(result)except Exception as err:print(err)def get_rice(self, name): # 偷好友大米try:_id_list = self.get_city_list("获取好友大米id")for _id in _id_list:payload = f"&friend_id={_id}"response = requests.post(url=self.url("users/get-rice"), headers=self.headers(), data=payload)result = response.json()# print(result)if result['code'] == 1:msg(f"{name}: {result['msg']},当前已有大米 {result['data']['sign_rice_num']}")time.sleep(5)elif result['code'] == 0:msg(f"{name}: {result['msg']}")else:msg(f"{name}: 失败, 请稍后再试!")print(result)except Exception as err:print(err)def get_city_list(self, name): # 获取好友大米idtry:response = requests.get(url=self.url("users/same-city-list"), headers=self.headers(), verify=False)result = response.json()if result['code'] == 1:_list = result['data']# print(_list)random_list = random.sample(range(1, 10), 3)_id_list = []for i in random_list:_id = _list[i]['id']_id_list.append(_id)return _id_listelif result['code'] == 0:msg(f"{name}: 获取列表失败!")else:msg(f"{name}: 失败, 请稍后再试!")print(result)except Exception as err:print(err)def browse_recipes(self, name): # 浏览菜谱try:payload = "&id=8&other_id=3"response = requests.post(url=self.url("task/link-task"), headers=self.headers(), data=payload)result = response.json()# print(result)if result['code'] == 1:msg(f"{name}: {result['msg']}")time.sleep(3)else:msg(f"{name}: 失败, 请稍后再试!")msg(result)except Exception as err:print(err)def get_index_info(self, name): # 获取可收取大米信息try:response = requests.get(url=self.url("index/index"), headers=self.headers(), verify=False)result = response.json()# print(result)rice_list = result['data']['rice_list']if result['code'] == 1 and len(rice_list) > 0:for i in range(len(rice_list)):_id, num, collect_name = rice_list[i]["id"], rice_list[i]["num"], rice_list[i]["name"]# print(_id, num, _name)self.collect_rice("收大米", _id, num, collect_name)elif result['code'] == 1 and len(rice_list) == 0:msg(f"{name}: 没有可以收获的大米")elif result['code'] == 2:msg(f"{name}: {result['msg']}, 请自己先打开一次小程序,种大米后在执行脚本!")else:msg(f"{name}: 失败, 请稍后再试!")msg(result)except Exception as err:print(err)def collect_rice(self, name, _id, num, collect_name): # 收大米try:payload = f"&id={_id}"response = requests.post(url=self.url("index/collect-rice"), headers=self.headers(), data=payload)result = response.json()# print(result)if result['code'] == 1:msg(f"{name}: 收取 {collect_name}{num} 大米, {result['msg']}")time.sleep(5)elif result['code'] == 0:msg(f"{name}: {result['msg']}")else:msg(f"{name}: 失败, 请稍后再试!")msg(result)except Exception as err:print(err)# ====================================================================def main():passdef last_version(name, mold):url = ''if mold == 1:url = f"https://raw.gh.fakev.cn/yml2213/Python/master/{name}/{name}.py"elif mold == 2:url = f"http://yml-gitea.ml:2233/yml/Python/raw/branch/master/{name}.py"try:_url = url_headers = {}response = requests.get(url=_url, headers=_headers, verify=False)result = response.textr = re.compile(r'Script_Version = "(.*?)"')_data = r.findall(result)if not _data:return "出现未知错误 ,请稍后重试!"else:return _data[0]except Exception as err:print(err)def mac_env(name):global ckArrpwd = os.path.dirname(os.path.abspath(__file__)) + os.seppath = pwd + ".env"with open(path, "r+") as f:env = f.read()if name in env:r = re.compile(r'sbr_data="(.*?)"', re.M | re.S | re.I)result = r.findall(env)# print(data[0])if "@" in result[0]:_ck = result[0].split("@")ckArr = _ckelif "\n" in result[0]:_ck = result[0].splitlines()ckArr = _ckelse:ckArr = resultelse:print(f"检查变量 {name} 是否已填写")def ql_env(name):global ckArrif name in os.environ:ckArr = []_data = os.environ[name]if "@" in _data:_ck = _data.split("@")ckArr = _ckelif "\n" in _data:_ck = _data.splitlines()ckArr = _ckelse:ckArr = _data.split("@")# 通知服务class Msg(object):def __init__(self, m=''):self.str_msg = mself.message()# noinspection PyMethodMayBeStaticdef get_sendnotify(self):if not os.path.exists("sendNotify.py"):cur_path = os.getcwd()print(f"未找到通知依赖文件,将于脚本执行目录({cur_path})新建:sendNotify.py ")try:url = 'https://raw.gh.fakev.cn/yml2213/Python/master/sendNotify.py'response = requests.get(url)with open('sendNotify.py', "w+", encoding="utf-8") as f:f.write(response.text)except Exception as err:print(err)else:print("文件已存在,跳过")passpassdef message(self):global msg_infoprint(self.str_msg)try:# msg_info = ''msg_info = f"{msg_info}\n{self.str_msg}"except Exception as err:print(err)msg_info = "{}".format(self.str_msg)sys.stdout.flush()# 这代码的作用就是刷新缓冲区。# 当我们打印一些字符时 ,并不是调用print函数后就立即打印的。一般会先将字符送到缓冲区 ,然后再打印。# 这就存在一个问题 ,如果你想等时间间隔的打印一些字符 ,但由于缓冲区没满 ,不会打印。就需要采取一些手段。如每次打印后强行刷新缓冲区。def main(self):global sendcur_path = os.getcwd()# print(cur_path)if os.path.exists(cur_path + "/sendNotify.py"):# noinspection PyBroadExceptiontry:from sendNotify import sendexcept Exception as err:self.get_sendnotify()print(err)try:from sendNotify import sendexcept Exception as err:print(err)print("加载通知服务失败~")else:self.get_sendnotify()try:from sendNotify import sendexcept Exception as err:print(err)print("加载通知服务失败~")Msg().main()def msg(data):Msg(data)# mac_env(f"{Name_Pinyin}_data")ql_env(f"{Name_Pinyin}_data")def tip():print("================ 脚本只支持青龙新版 =================")print("============ 具体教程以请自行查看顶部教程 =============\n")msg(f"🔔 {Script_Name} ,开始! ")origin_version = last_version(Name_Pinyin, 1)msg(f"📌 本地脚本: {Script_Version} 远程仓库版本: V {origin_version}")msg(f"📌 🆙 更新内容: {Script_Change}")msg(f"共发现 {str(len(ckArr))} 个账号")if __name__ == "__main__":global ckArr, msg_info, send, _ck_statetip()start()send(f"{Script_Name}", msg_info)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。