def run(self): try: self.main() except Exception as error: message_context = f'运行异常,脚本又挂掉啦~' tools.send_message(self.log_head + message_context) print(error)
def run(self): try: self.open_database() self.get_latest_rate() self.close_database() except Exception: message_context = f'运行异常,脚本又挂掉啦~' tools.send_message(self.log_head + message_context)
def run(self): try: self.get_mkgal_sign() self.get_mkgal_addJf() except Exception as error: message_context = f'运行异常,脚本又挂掉啦~' tools.send_message(self.log_head + message_context) print(error)
def get_mkgal_addJf(self): url = 'https://www.mikugal.com/addJf' headers = { 'Connection': 'keep-alive', 'Accept': 'application/json, text/plain, */*', 'X-Auth-Token': self.sign_token, 'Sec-Fetch-Dest': 'empty', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36', 'Sec-Fetch-Site': 'same-origin', 'Sec-Fetch-Mode': 'cors', 'Referer': 'https://www.mikugal.com/', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8' } response = self.session.get(url=url, headers=headers).json() if response['code'] == 0: message_context = f'每日签到成功' else: message_context = f'每日签到失败' tools.send_message(self.log_head + message_context)
def get_mkgal_sign(self): url = 'https://www.mikugal.com/sign' headers = { 'Connection': 'keep-alive', 'Accept': 'application/json, text/plain, */*', 'Origin': 'https://www.mikugal.com', 'Sec-Fetch-Dest': 'empty', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded', 'Sec-Fetch-Site': 'same-origin', 'Sec-Fetch-Mode': 'cors', 'Referer': 'https://www.mikugal.com/', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8' } data = {'email': self.email, 'password': self.password} response = self.session.post(url=url, headers=headers, data=data) response_json = response.json()['obj'] message_context = f'用户名:{response_json["nickname"]} 当前金币:{response_json["jf"]} + {response_json["qs"]}' tools.send_message(self.log_head + message_context) self.sign_token = response_json["token"]
def login(self): url = "https://cloud.189.cn/udb/udb_login.jsp?pageId=1&redirectURL=/main.action" response = self.session.get(url) captcha_token = re.findall( r"captchaToken' value='(.+?)'", response.text)[0] lt = re.findall(r'lt = "(.+?)"', response.text)[0] return_url = re.findall(r"returnUrl = '(.+?)'", response.text)[0] param_id = re.findall(r'paramId = "(.+?)"', response.text)[0] j_rsakey = re.findall( r'j_rsaKey" value="(\S+)"', response.text, re.M)[0] self.session.headers.update({"lt": lt}) url = "https://open.e.189.cn/api/logbox/oauth2/loginSubmit.do" headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/76.0', 'Referer': 'https://open.e.189.cn/', } data = { "appKey": "cloud", "accountType": '01', "userName": f"{{RSA}}{self.rsa_encode(j_rsakey, self.email)}", "password": f"{{RSA}}{self.rsa_encode(j_rsakey, self.password)}", "validateCode": "", "captchaToken": captcha_token, "returnUrl": return_url, "mailSuffix": "@189.cn", "paramId": param_id } response = self.session.post( url, data=data, headers=headers, timeout=10) if(response.json()['result'] == 0): redirect_url = response.json()['toUrl'] self.session.get(redirect_url) message_context = f'帐号登录成功' tools.send_message(self.log_head + message_context) return True else: message_context = f'帐号登录失败' tools.send_message(self.log_head + message_context) return False
def main(self): if self.login(): rand = str(round(time.time()*1000)) surl = f'https://api.cloud.189.cn/mkt/userSign.action?rand={rand}&clientType=TELEANDROID&version=8.6.3&model=SM-G930K' url = f'https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_SIGNIN&activityId=ACT_SIGNIN' url2 = f'https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_SIGNIN_PHOTOS&activityId=ACT_SIGNIN' headers = { 'User-Agent': 'Mozilla/5.0 (Linux; Android 5.1.1; SM-G930K Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36 Ecloud/8.6.3 Android/22 clientId/355325117317828 clientModel/SM-G930K imsi/460071114317824 clientChannelId/qq proVersion/1.0.6', "Referer": "https://m.cloud.189.cn/zhuanti/2016/sign/index.jsp?albumBackupOpened=1", "Host": "m.cloud.189.cn", "Accept-Encoding": "gzip, deflate", } response = self.session.get(surl, headers=headers) netdiskBonus = response.json()['netdiskBonus'] if(response.json()['isSign'] == "false"): message_context = f'未签到,签到获得{netdiskBonus}M空间' else: message_context = f'已签到,签到获得{netdiskBonus}M空间' tools.send_message(self.log_head + message_context) headers = { 'User-Agent': 'Mozilla/5.0 (Linux; Android 5.1.1; SM-G930K Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36 Ecloud/8.6.3 Android/22 clientId/355325117317828 clientModel/SM-G930K imsi/460071114317824 clientChannelId/qq proVersion/1.0.6', "Referer": "https://m.cloud.189.cn/zhuanti/2016/sign/index.jsp?albumBackupOpened=1", "Host": "m.cloud.189.cn", "Accept-Encoding": "gzip, deflate", } response = self.session.get(url, headers=headers) if ("errorCode" in response.text): if(response.json()['errorCode'] == "User_Not_Chance"): message_context = f'第一次抽奖次数不足' else: message_context = f'第一次抽奖失败' else: description = response.json()['description'] message_context = f'第一次抽奖抽奖获得{description}' tools.send_message(self.log_head + message_context) response = self.session.get(url2, headers=headers) if ("errorCode" in response.text): if(response.json()['errorCode'] == "User_Not_Chance"): message_context = f'第二次抽奖次数不足' else: message_context = f'第二次抽奖失败' else: description = response.json()['description'] message_context = f'第二次抽奖抽奖获得{description}' tools.send_message(self.log_head + message_context)
def get_tbs(self): headers = copy.copy(self.HEADERS) headers.update({ self.COOKIE: self.EMPTY_STR.join([self.BDUSS, self.EQUAL, self.bduss]) }) try: tbs = self.session.get(url=self.TBS_URL, headers=headers, timeout=5).json()[self.TBS] except Exception as error: tools.send_message(self.log_head + '获取tbs出错') tools.send_message(self.log_head + '重新获取tbs开始') tbs = self.session.get(url=self.TBS_URL, headers=headers, timeout=5).json()[self.TBS] tools.send_message(self.log_head + f'获取TBS:{tbs}') return tbs
def get_favorite(self): i = 1 data = { 'BDUSS': self.bduss, '_client_type': '2', '_client_id': 'wappc_1534235498291_488', '_client_version': '9.7.8.0', '_phone_imei': '000000000000000', 'from': '1008621y', 'page_no': '1', 'page_size': '200', 'model': 'MI+5', 'net_type': '1', 'timestamp': str(int(time.time())), 'vcode_tag': '11', } res = self.session.post(url=self.LIKIE_URL, data=self.encodeData(data), timeout=5).json() returnData = {} returnData = res if 'forum_list' not in returnData: returnData['forum_list'] = [] if res['forum_list'] == []: return {'gconforum': [], 'non-gconforum': []} if 'non-gconforum' not in returnData['forum_list']: returnData['forum_list']['non-gconforum'] = [] if 'gconforum' not in returnData['forum_list']: returnData['forum_list']['gconforum'] = [] while 'has_more' in res and res['has_more'] == '1': i = i + 1 data = { 'BDUSS': self.bduss, '_client_type': '2', '_client_id': 'wappc_1534235498291_488', '_client_version': '9.7.8.0', '_phone_imei': '000000000000000', 'from': '1008621y', 'page_no': str(i), 'page_size': '200', 'model': 'MI+5', 'net_type': '1', 'timestamp': str(int(time.time())), 'vcode_tag': '11', } data = self.encodeData(data) try: res = self.session.post(url=self.LIKIE_URL, data=data, timeout=5).json() except Exception as error: tools.send_message(self.log_head + '获取关注的贴吧出错') continue if 'forum_list' not in res: continue if 'non-gconforum' in res['forum_list']: returnData['forum_list']['non-gconforum'].append( res['forum_list']['non-gconforum']) if 'gconforum' in res['forum_list']: returnData['forum_list']['gconforum'].append( res['forum_list']['gconforum']) t = [] for i in returnData['forum_list']['non-gconforum']: if isinstance(i, list): for j in i: if isinstance(j, list): for k in j: t.append(k) else: t.append(j) else: t.append(i) for i in returnData['forum_list']['gconforum']: if isinstance(i, list): for j in i: if isinstance(j, list): for k in j: t.append(k) else: t.append(j) else: t.append(i) tools.send_message(self.log_head + f'获取关注的贴吧: {len(t)} 个') return t
def main(self): tbs = self.get_tbs() favorites = self.get_favorite() for j in favorites: self.client_sign(tbs, tbs, j["id"], j["name"]) tools.send_message(self.log_head + '签到结束')