def run(self):
        info_list = self.get_info()
        message_list = []
        if info_list:
            today = info_list.get('data', {}).get('today')
            total_sign_day = info_list.get('data', {}).get('total_sign_day')
            awards = Roles(self._cookie).get_awards().get('data',
                                                          {}).get('awards')
            uid = str(self.uid).replace(str(self.uid)[1:7], '******', 1)

            log.info(f'Checking in account id {uid}...')
            time.sleep(10)
            message = {
                'today': today,
                'region_name': '',
                'uid': uid,
                'total_sign_day': total_sign_day,
                'end': '',
            }
            if info_list.get('data', {}).get('is_sign') is True:
                message['award_name'] = awards[total_sign_day - 1]['name']
                message['award_cnt'] = awards[total_sign_day - 1]['cnt']
                message[
                    'status'] = f"Traveler, you've already checked in today"
                message_list.append(self.message.format(**message))
                return ''.join(message_list)
            else:
                message['award_name'] = awards[total_sign_day]['name']
                message['award_cnt'] = awards[total_sign_day]['cnt']
            if info_list.get('data', {}).get('first_bind') is True:
                message['status'] = f'Please check in manually once'
                message_list.append(self.message.format(**message))
                return ''.join(message_list)

            data = {'act_id': CONFIG.OS_ACT_ID}

            try:
                response = req.to_python(
                    req.request('post',
                                CONFIG.OS_SIGN_URL,
                                headers=self.get_header(),
                                data=json.dumps(data,
                                                ensure_ascii=False)).text)
            except Exception as e:
                raise
            code = response.get('retcode', 99999)
            # 0:      success
            # -5003:  already checked in
            if code != 0:
                message_list.append(response)
                return ''.join(message_list)
            message['total_sign_day'] = total_sign_day + 1
            message['status'] = response['message']
            message_list.append(self.message.format(**message))
        log.info('Check-in complete')

        return ''.join(message_list)
 def get_info(self):
     info_url = CONFIG.OS_INFO_URL
     try:
         response = req.request('get', info_url,
                                headers=self.get_header()).text
         return req.to_python(response)
     except Exception as e:
         log.error('failure in get_info')
         raise
    def get_awards(self):
        response = {}
        try:
            response = req.to_python(
                req.request('get', CONFIG.AWARD_URL,
                            headers=self.get_header()).text)
        except json.JSONDecodeError as e:
            raise Exception(e)

        return response
Example #4
0
File: weibo.py Project: fluteds/gih
    def get_code(self, id):
        item = f'🎁 {id}'
        log.info(f'Ready to receive {item} redemption code...')
        data = {'gid': 10725, 'itemId': id, 'channel': 'wblink'}
        self.header['Referer'] = f'https://ka.sina.com.cn/html5/gift/{id}'
        self.header['Cookie'] = self.ka_cookie

        retry = 3
        sec = 5
        for i in range(retry):
            sleep(sec)
            log.info(f'♻️ First {i + 1} to receive {id} redemption code...')
            try:
                response = req.to_python(
                    req.request('get',
                                CONFIG.KA_URL,
                                params=data,
                                headers=self.header).text)
            except Exception as e:
                log.error(e)
            else:
                if response.get('k'):
                    log.info(f'{item} Redemption code to receive success')
                    return response['data']['kahao']
                elif response.get(
                        'code') == '2002' and 'Avatar' in response.get(
                            'msg', ''):
                    log.error(
                        f'🥳 {id}: I can only receive once or the redemption code has already been received.'
                    )
                    break
                elif response.get(
                        'code'
                ) == '2002' and 'Sign in' or 'Not yet' in response.get(
                        'msg', ''):
                    log.error(f'😳 {id}: {response["msg"]}')
                    break
                elif response.get('code') == '2002':
                    log.error(f'😳 {id}: {response["msg"]}')
                elif 'login' in response.get('msg', ''):
                    log.error('Login failure, please login again')
                    return
                else:
                    log.error(f'😳 {id}: {response}')

                if i + 1 != retry:
                    log.info(
                        f'will be {sec} Retry after the timer runs out...')
                else:
                    log.error(
                        f'🚫 {id}: Failure! Number reached the upper limit, Aborting redeem code'
                    )

        log.info('The redemption code is acquired')
        return
    def get_info(self):
        log.info('Prêt à recevoir les informations de connexion...')
        info_url = CONFIG.OS_INFO_URL
        try:
            response = req.request('get', info_url,
                                   headers=self.get_header()).text
        except Exception as e:
            raise Exception(e)

        log.info('Les informations de connexion ont été obtenues.')
        return req.to_python(response)
Example #6
0
    def get_info(self):
        log.info('Ready to get check-in information...')
        info_url = CONFIG.OS_INFO_URL
        try:
            response = req.request('get', info_url,
                                   headers=self.get_header()).text
        except Exception as e:
            raise Exception(e)

        log.info('The sign-in information has been successfully acquired')
        return req.to_python(response)
    def get_info(self):
        log.info('准备获取签到信息...')
        info_url = CONFIG.OS_INFO_URL
        try:
            response = req.request('get', info_url,
                                   headers=self.get_header()).json()
        except Exception as e:
            raise Exception(e)

        log.info('签到信息获取完毕')
        return response
Example #8
0
    def get_roles(self):
        log.info('准备获取账号信息...')
        response = {}
        try:
            response = req.to_python(req.request(
                'get', CONFIG.ROLE_URL, headers=self.get_header()).text)
            message = response['message']
        except Exception as e:
            raise Exception(e)
        if response.get(
            'retcode', 1) != 0 or response.get('data', None) is None:
            raise Exception(message)

        log.info('账号信息获取完毕')
        return response
Example #9
0
    def get_code(self, id):
        item = f'🎁 {id}'
        log.info(f'准备领取 {item} 的兑换码...')
        data = {'gid': 10725, 'itemId': id, 'channel': 'wblink'}
        self.header['Referer'] = f'https://ka.sina.com.cn/html5/gift/{id}'
        self.header['Cookie'] = self.ka_cookie

        retry = 3
        sec = 5
        for i in range(retry):
            sleep(sec)
            log.info(f'♻️ 第 {i + 1} 次领取 {id} 的兑换码...')
            try:
                response = req.to_python(
                    req.request('get',
                                CONFIG.KA_URL,
                                params=data,
                                headers=self.header).text)
            except Exception as e:
                log.error(e)
            else:
                if response.get('k'):
                    log.info(f'{item} 的兑换码领取成功')
                    return response['data']['kahao']
                elif response.get('code') == '2002' and '头像' in response.get(
                        'msg', ''):
                    log.error(f'🥳 {id}: 每天只能领取一张或该兑换码已经领取过了哦')
                    break
                elif response.get(
                        'code') == '2002' and '签到' or '尚未' in response.get(
                            'msg', ''):
                    log.error(f'😳 {id}: {response["msg"]}')
                    break
                elif response.get('code') == '2002':
                    log.error(f'😳 {id}: {response["msg"]}')
                elif 'login' in response.get('msg', ''):
                    log.error('登录失效, 请重新登录')
                    return
                else:
                    log.error(f'😳 {id}: {response}')

                if i + 1 != retry:
                    log.info(f'将在 {sec} 秒后重试...')
                else:
                    log.error(f'🚫 {id}: 失败次数达到上限, 放弃领取该兑换码')

        log.info('兑换码获取完毕')
        return
Example #10
0
    def get_super_list(self):
        log.info('准备获取超话列表...')
        try:
            response = req.request('get', CONFIG.SUPER_URL,
                headers=self.get_header(), allow_redirects=False)
        except Exception as e:
            log.error(e)
        else:
            if response.status_code == 200:
                log.info('🥳 weibo: 超话列表获取成功')
                return req.to_python(response.text)
            elif response.status_code == 302:
                log.error('😳 weibo: 登录可能失效, 尝试重新登录')
            else:
                log.error('😳 weibo: 超话列表获取失败')

        log.info('超话列表获取完毕')
        return
Example #11
0
File: weibo.py Project: fluteds/gih
    def get_super_list(self):
        log.info('Prepare to get a list of devices...')
        try:
            response = req.request('get',
                                   CONFIG.SUPER_URL,
                                   headers=self.get_header(),
                                   allow_redirects=False)
        except Exception as e:
            log.error(e)
        else:
            if response.status_code == 200:
                log.info('🥳 weibo: Superphracted list acquisition success')
                return req.to_python(response.text)
            elif response.status_code == 302:
                log.error('😳 weibo: Login may fail, try to log in again')
            else:
                log.error('😳 weibo: Super words list acquisition failed')

        log.info('Super words list')
        return
Example #12
0
    def get_id(self):
        log.info('准备获取活动信息...')
        id_list = []
        try:
            response = req.to_python(req.request(
                'get', CONFIG.YS_URL, headers=self.header).text)
            group = response['data']['cards'][3]['card_group'][0]['group']
        except Exception as e:
            log.error(f'活动信息获取失败:\n{e}')
        else:
            for ids in group:
                if '礼包' in ids.get('title_sub', ''):
                    id = re.findall('(?<=gift\/)(.*)\?channel', ids['scheme'])[0]
                    log.info(f'└─🎁 {ids["title_sub"]}')
                    id_list.append(id)
            if not id_list:
                log.info('原神超话暂无活动')

        log.info('活动信息获取完毕')
        return id_list
Example #13
0
 def get_region_name(self):
     region_name_url = CONFIG.OS_ROLE_URL
     try:
         response = req.request('get',
                                region_name_url,
                                headers=self.get_header()).text
         # get region_name base on highest character level in the server
         character_list = req.to_python(response).get('data',
                                                      {}).get('list')
         if len(character_list) == 1:
             return character_list[0]['region_name']
         main_character_level = 0
         region_name = ''
         for data in character_list:
             if data['level'] > main_character_level:
                 main_character_level = data['level']
                 region_name = data['region_name']
         return region_name
     except Exception as e:
         log.error('failure in get_region_name')
         raise
 def pushTemplate(self, method, url, params=None, data=None, json=None, headers=None, **kwargs):
     name = kwargs.get('name')
     # needs = kwargs.get('needs')
     token = kwargs.get('token')
     text = kwargs.get('text')
     code = kwargs.get('code')
     if not token:
         log.info(f'{name} SKIPPED')
         return False
     try:
         response = req.to_python(req.request(
             method, url, 2, params, data, json, headers).text)
         rspcode = response[text]
     except Exception as e:
         log.error(f'{name} FAILED\n{e}')
     else:
         if rspcode == code:
             log.info(f'{name} SUCCESS')
         else:
             log.error(f'{name} FAILED\n{response}')
     return True
Example #15
0
File: weibo.py Project: fluteds/gih
    def get_id(self):
        log.info('Preparing to obtain activity information...')
        id_list = []
        try:
            response = req.to_python(
                req.request('get', CONFIG.YS_URL, headers=self.header).text)
            group = response['data']['cards'][3]['card_group'][0]['group']
        except Exception as e:
            log.error(f'Activity information failure:\n{e}')
        else:
            for ids in group:
                if 'Package' in ids.get('title_sub', ''):
                    id = re.findall('(?<=gift\/)(.*)\?channel',
                                    ids['scheme'])[0]
                    log.info(f'└─🎁 {ids["title_sub"]}')
                    id_list.append(id)
            if not id_list:
                log.info('Original God overtime')

        log.info('The activity information is acquired')
        return id_list
Example #16
0
File: weibo.py Project: fluteds/gih
    def get_box_code(self):
        log.info(
            'Preparing to get the redemption code of "Personal Center"...')
        id_list = []
        code_list = []
        self.header['Referer'] = f'https://ka.sina.com.cn/html5/'
        self.header['Cookie'] = self.ka_cookie
        try:
            response = req.request('get',
                                   CONFIG.BOX_URL,
                                   headers=self.header,
                                   allow_redirects=False)
        except Exception as e:
            log.error(e)
        else:
            if response.status_code == 200:
                response.encoding = 'utf-8'
                soup = BeautifulSoup(response.text, 'html.parser')
                # print(soup.prettify())
                boxs = soup.find_all(class_='giftbag')
                for box in boxs:
                    item = {
                        'id': box.find(class_='deleBtn').get('data-itemid'),
                        'title': box.find(class_='title itemTitle').text,
                        'code': box.find('span').parent.contents[1]
                    }
                    log.info(f'└─☁️{item["title"]}')
                    id_list.append(item['id'])
                    code_list.append(item)
                code_list.insert(0, id_list)
            elif response.status_code == 302:
                log.error('😳 ka.sina: Login may fail, try to log in again')
            else:
                log.error('😳 ka.sina: Redemption code acquisition failed')

        # Print exchange code
        # print(req.to_json(code_list))

        log.info('"Personal Center" redemption code is acquired')
        return code_list
Example #17
0
    def get_box_code(self):
        log.info('准备获取「个人中心」的兑换码...')
        id_list = []
        code_list = []
        self.header['Referer'] = f'https://ka.sina.com.cn/html5/'
        self.header['Cookie'] = self.ka_cookie
        try:
            response = req.request('get',
                                   CONFIG.BOX_URL,
                                   headers=self.header,
                                   allow_redirects=False)
        except Exception as e:
            log.error(e)
        else:
            if response.status_code == 200:
                response.encoding = 'utf-8'
                soup = BeautifulSoup(response.text, 'html.parser')
                # print(soup.prettify())
                boxs = soup.find_all(class_='giftbag')
                for box in boxs:
                    item = {
                        'id': box.find(class_='deleBtn').get('data-itemid'),
                        'title': box.find(class_='title itemTitle').text,
                        'code': box.find('span').parent.contents[1]
                    }
                    # log.info(f'└─💌 {item["id"]}')
                    id_list.append(
                        box.find(class_='deleBtn').get('data-itemid'))
                    code_list.append(item)
                code_list.insert(0, id_list)
            elif response.status_code == 302:
                log.error('😳 ka.sina: 登录可能失效, 尝试重新登录')
            else:
                log.error('😳 ka.sina: 兑换码获取失败')

        # 打印兑换码
        # print(req.to_json(code_list))

        log.info('「个人中心」的兑换码获取完毕')
        return code_list
Example #18
0
 def pushTemplate(self,
                  method,
                  url,
                  params=None,
                  data=None,
                  json=None,
                  headers=None,
                  **kwargs):
     name = kwargs.get('name')
     # needs = kwargs.get('needs')
     token = kwargs.get('token')
     text = kwargs.get('text')
     code = kwargs.get('code')
     if not token:
         log.info(f'{name} 🚫')
         # log.info (f '{name} The {NEDS} needed to push the {NEEDS} is not set, you are skipping ...')
         return
     try:
         response = req.to_python(
             req.request(method, url, 2, params, data, json, headers).text)
         rspcode = response[text]
     except Exception as e:
         # 🚫:disabled; 🥳:success; 😳:fail;
         log.error(f'{name} 😳\n{e}')
     else:
         if rspcode == code:
             log.info(f'{name} 🥳')
         # Telegram Bot
         elif name == 'Telegram Bot' and rspcode:
             log.info(f'{name} 🥳')
         elif name == 'Telegram Bot' and response[code] == 400:
             log.error(
                 f'{name} 😳\n Please take the initiative bot, send a message and check if the TG_USER_ID is right or not'
             )
         elif name == 'Telegram Bot' and response[code] == 401:
             log.error(f'{name} 😳\nTG_BOT_TOKEN error')
         else:
             log.error(f'{name} 😳\n{response}')
Example #19
0
 def pushTemplate(self,
                  method,
                  url,
                  params=None,
                  data=None,
                  json=None,
                  headers=None,
                  **kwargs):
     name = kwargs.get('name')
     # needs = kwargs.get('needs')
     token = kwargs.get('token')
     text = kwargs.get('text')
     code = kwargs.get('code')
     if not token:
         log.info(f'{name} 🚫')
         # log.info(f'{name} 推送所需的 {needs} 未设置, 正在跳过...')
         return
     try:
         response = req.to_python(
             req.request(method, url, 2, params, data, json, headers).text)
         rspcode = response[text]
     except Exception as e:
         # 🚫: disabled; 🥳:success; 😳:fail
         log.error(f'{name} 😳\n{e}')
     else:
         if rspcode == code:
             log.info(f'{name} 🥳')
         # Telegram Bot
         elif name == 'Telegram Bot' and rspcode:
             log.info(f'{name} 🥳')
         elif name == 'Telegram Bot' and response[code] == 400:
             log.error(f'{name} 😳\n请主动给 bot 发送一条消息并检查 TG_USER_ID 是否正确')
         elif name == 'Telegram Bot' and response[code] == 401:
             log.error(f'{name} 😳\nTG_BOT_TOKEN 错误')
         else:
             log.error(f'{name} 😳\n{response}')
Example #20
0
    def run(self):
        info_list = self.get_info()
        message_list = []
        for i in range(len(info_list)):
            today = info_list[i]['data']['today']
            total_sign_day = info_list[i]['data']['total_sign_day']
            awards = Roles(self._cookie).get_awards()['data']['awards']
            uid = str(self._uid_list[i]).replace(
                str(self._uid_list[i])[1:8], '******', 1)

            log.info(f'准备为旅行者 {i + 1} 号签到...')
            time.sleep(10)
            message = {
                'today': today,
                'region_name': self._region_name_list[i],
                'uid': uid,
                'total_sign_day': total_sign_day,
                'total_day': date.today().day,
                'end': '',
            }
            if info_list[i]['data']['is_sign'] is True:
                message['award_name'] = awards[total_sign_day - 1]['name']
                message['award_cnt'] = awards[total_sign_day - 1]['cnt']
                message['status'] = f'👀 旅行者 {i + 1} 号, 你已经签到过了哦'
                message_list.append(self.message.format(**message))
                continue
            else:
                message['award_name'] = awards[total_sign_day]['name']
                message['award_cnt'] = awards[total_sign_day]['cnt']
            if info_list[i]['data']['first_bind'] is True:
                message['status'] = f'💪 旅行者 {i + 1} 号, 请先前往米游社App手动签到一次'
                message_list.append(self.message.format(**message))
                continue

            data = {
                'act_id': CONFIG.ACT_ID,
                'region': self._region_list[i],
                'uid': self._uid_list[i]
            }

            try:
                response = req.to_python(
                    req.request('post',
                                CONFIG.SIGN_URL,
                                headers=self.get_header(),
                                data=json.dumps(data,
                                                ensure_ascii=False)).text)
            except Exception as e:
                raise Exception(e)
            code = response.get('retcode', 99999)
            # 0:      success
            # -5003:  already signed in
            if code != 0:
                message_list.append(response)
                continue
            message['total_sign_day'] = total_sign_day + 1
            message['status'] = response['message']
            message_list.append(self.message.format(**message))
        log.info('签到完毕')

        return ''.join(message_list)