Пример #1
0
    def super_sign(self):
        follow_list = self.resolve_data()
        if not follow_list:
            log.info('Remove Weibo Super Turial Sign')
            return
        for follow in follow_list:
            lv = f'[Lv.{follow["lv"]}]'
            name = follow['title_sub']
            log.info(f'Ready for {name} Overturning...')
            sleep(5)
            if follow['is_sign'] == 'Is signed in':
                log.info(f'👀 {lv}{name}: Has been signed in')
                continue
            elif follow['is_sign'] == 'Sign in':
                url = follow['sign_url']
                try:
                    response = req.to_python(
                        req.request('post', url,
                                    headers=self.get_header()).text)
                except Exception as e:
                    log.error(e)
                else:
                    if response['ok'] == 1:
                        log.info(f'🥳 {lv}{name}: Sign in success')
                    else:
                        log.info(f'😳 {lv}{name}: Sign in failure\n{response}')

        log.info('Weibo is completed')
        return
Пример #2
0
    def resolve_data(self):
        super_list = self.get_super_list()
        if not super_list:
            log.info('Cancel the analysis of data information')
            return
        log.info('Prepare to parse data information...')
        follow_list = []
        try:
            card_group = super_list['data']['cards'][0]['card_group'][1:-1]
        except Exception as e:
            log.error(e)
        else:
            for card in card_group:
                follow = {
                    'title_sub': card['title_sub'],
                    'containerid': card['scheme'].split('&')[0].split('=')[1],
                    'lv': int(re.findall('\d+', card['desc1'])[0]),
                    'is_sign': card['buttons'][0]['name'],
                    'sign_url': False
                }
                scheme = card['buttons'][0]['scheme']
                if scheme:
                    follow['sign_url'] = f'https://m.weibo.cn{scheme}'
                follow_list.append(follow)
        log.info(f'Resolve {len(follow_list)} article data')
        if follow_list:
            for follow in follow_list:
                log.info(f'⚜️ [Lv.{follow["lv"]}]{follow["title_sub"]}')

        log.info('Data information parsing is completed')
        return follow_list
Пример #3
0
 def ddBot(self, text, status, desp):
     if Notify.DD_BOT_TOKEN != '':
         url = 'https://oapi.dingtalk.com/robot/send?access_token={}'.format(
             Notify.DD_BOT_TOKEN)
         data = {
             'msgtype': 'text',
             'text': {
                 'content': '{} {}\n\n{}'.format(text, status, desp)
             }
         }
         if Notify.DD_BOT_SECRET != '':
             secret = Notify.DD_BOT_SECRET
             timestamp = int(round(time.time() * 1000))
             secret_enc = bytes(secret).encode('utf-8')
             string_to_sign = '{}\n{}'.format(timestamp, secret)
             string_to_sign_enc = bytes(string_to_sign).encode('utf-8')
             hmac_code = hmac.new(secret_enc,
                                  string_to_sign_enc,
                                  digestmod=hashlib.sha256).digest()
             sign = parse.quote_plus(base64.b64encode(hmac_code))
             url = 'https://oapi.dingtalk.com/robot/send?access_token={}&timestamp={}&sign={}'.format(
                 Notify.DD_BOT_TOKEN, timestamp, sign)
         try:
             response = self.to_python(requests.post(url, data=data).text)
         except Exception as e:
             log.error(e)
             raise HTTPError
         else:
             if response['errcode'] == 0:
                 log.info('钉钉推送成功')
             else:
                 log.error('钉钉推送失败:\n{}'.format(response))
     else:
         log.info('您未配置钉钉推送所需的DD_BOT_TOKEN或DD_BOT_SECRET,取消钉钉推送')
         pass
Пример #4
0
 def POST(self):
     web.header("Content-Type","text/html; charset=utf-8")
     form = forms.nas_add_form()
     if not form.validates(): 
         return render("baseform.html",form=form,title="新增NAS设备",action="/nas/add")    
     else:
         db = get_db()
         if db.query(models.RadNas).filter(models.RadNas.ip_addr == form.d.ip_addr).count()>0:
             return errorpage("Nas %s 已经存在"%form.d.ip_addr)       
         try:
             nas = models.RadNas()
             nas.id = nextid()
             nas.ip_addr = form.d.ip_addr
             nas.name = form.d.name
             nas.auth_secret = form.d.auth_secret
             nas.acct_secret = form.d.acct_secret
             nas.vendor_id = form.d.vendor_id
             nas.time_type = form.d.time_type
             nas.status = form.d.status
             db.add(nas)
             db.commit()
             db.flush()
         except Exception,e:
             db.rollback()
             log.error("add nes error: %s"%str(e))
             return errorpage("新增Nas失败 %s"%str(e))
         raise web.seeother("/nas",absolute=True)
Пример #5
0
    def get_wwtoken(self):
        WW_ID = self.WW_ID
        if 'WW_ID' in os.environ:
            WW_ID = os.environ['WW_ID']

        WW_APP_SECRET = self.WW_APP_SECRET
        if 'WW_APP_SECRET' in os.environ:
            WW_APP_SECRET = os.environ['WW_APP_SECRET']

        if WW_ID and WW_APP_SECRET:
            url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken'
            data = {'corpid': WW_ID, 'corpsecret': WW_APP_SECRET}

            try:
                response = req.to_python(
                    req.request('get', url, params=data).text)
                rspcode = response['errcode']
            except Exception as e:
                log.error(e)
            else:
                if rspcode == 0:
                    log.info('access_token 获取成功')
                    return response['access_token']
                else:
                    log.error(f'access_token 获取失败:\n{response}')
        else:
            log.info('企业微信应用 🚫')
Пример #6
0
    def POST(self,none):
        web.header("Content-Type","text/html; charset=utf-8")
        form = forms.product_update_form()
        if not form.validates(): 
            return render("baseform.html",form=form,title="修改产品套餐",action="/product/update/")    
        else:
            db = get_db()
            product = db.query(models.RadProduct).get(form.d.id)
            if not product:
                return errorpage("产品不存在")
            try:
                product.name = form.d.name
                product.fee_num = form.d.fee_num
                product.fee_price = int(Decimal(form.d.fee_price)*100)
                product.concur_number = form.d.concur_number
                product.bind_mac = form.d.bind_mac
                product.bind_vlan = form.d.bind_vlan
                product.bandwidth_code = form.d.bandwidth_code
                product.input_max_limit = form.d.input_max_limit
                product.output_max_limit = form.d.output_max_limit
                product.input_rate_code = form.d.input_rate_code
                product.output_rate_code = form.d.output_rate_code
                product.domain_code = form.d.domain_code
                product.status = 0
                db.commit()
                db.flush()
            except Exception,e:
                db.rollback()
                log.error("update product error: %s"%str(e))
                return errorpage("修改套餐失败 %s"%str(e))

            raise web.seeother("/product",absolute=True) 
Пример #7
0
def parse_wiki_event(date_str):
    for year, month, day in date_generator(date_str):
        event_date = '{}-{}-{}'.format(year, month, day)
        with PG_CONN.cursor() as cur:
            cmd = "SELECT event_raw FROM {table} where event_date='{event_date}' ORDER BY inserted_at DESC;"
            cmd = cmd.format(table=WIKIPEDIA_TABLE_RAW, event_date=event_date)
            cur.execute(cmd)

            event_raw = cur.fetchone()[0]

            soup = BeautifulSoup(event_raw, 'html.parser')

            try:
                event_table = soup.find('table', {'class': 'vevent'})
                event_types = event_table.find('td', {
                    'class': 'description'
                }).find_all('dl')
                event_types_str = [o.text.strip() for o in event_types]

                log.debug(event_types_str)

                events_uls = event_table.find('td', {
                    'class': 'description'
                }).select('> ul')
                #log.debug(events_uls)
                #log.debug(len(events_uls))
                # each ul correspond to an event_type
                # in one ul several events

                assert len(event_types_str) == len(events_uls)

                for event_type_str, uls in zip(event_types_str, events_uls):
                    for event in uls.select('> li'):
                        event_type = event_type_str
                        event_title = event.find('a').text
                        event_body = event.text
                        event_sources = [
                            get_domain_from_url(o['href'])
                            for o in event.find_all('a', {
                                'rel': 'nofollow',
                                'class': 'external text'
                            })
                        ]

                        cmd = (
                            'INSERT INTO {table} (event_date, event_type, event_title, event_body, event_sources) '
                            'VALUES (%s, %s, %s, %s, %s);')
                        cmd = cmd.format(table=WIKIPEDIA_TABLE_PARSED_STG)

                        cur.execute(cmd, (event_date, event_type, event_title,
                                          event_body, event_sources))
                        PG_CONN.commit()

                        print 'EVENT TYPE ', event_type
                        print 'EVENT TITLE ', event_title
                        print 'EVENT BODY', event_body
                        print 'EVENT SOURCES', event_sources

            except Exception, e:
                log.error('could not parse %s', event_date)
Пример #8
0
    def POST(self):
        web.header("Content-Type","text/html; charset=utf-8")
        form = forms.product_add_form()
        if not form.validates(): 
            return render("baseform.html",form=form,title="新增产品套餐",action="/product/add")    
        else:
            db = get_db()
            if db.query(models.RadProduct).filter(models.RadProduct.id == form.d.id).count()>0:
                return errorpage("产品编号重复")
            try:
                radproduct = models.RadProduct()
                radproduct.id = form.d.id
                radproduct.name = form.d.name
                radproduct.policy = form.d.policy
                radproduct.fee_num = form.d.fee_num
                radproduct.fee_price = int(Decimal(form.d.fee_price)*100)
                radproduct.concur_number = form.d.concur_number
                radproduct.bind_mac = form.d.bind_mac
                radproduct.bind_vlan = form.d.bind_vlan
                radproduct.bandwidth_code = form.d.bandwidth_code
                radproduct.input_max_limit = form.d.input_max_limit
                radproduct.output_max_limit = form.d.output_max_limit
                radproduct.input_rate_code = form.d.input_rate_code
                radproduct.output_rate_code = form.d.output_rate_code
                radproduct.domain_code = form.d.domain_code
                radproduct.status = 0
                db.add(radproduct)
                db.commit()
                db.flush()
            except Exception,e:
                db.rollback()
                log.error("add product error: %s"%str(e))
                return errorpage("产品新增失败 %s"%str(e))

            raise web.seeother("/product",absolute=True)             
Пример #9
0
 def run(self):
     """ run the case, after running, the statstical result is held in self.data as list
     """
     #CaseTemplate.LiveN += 1
     log.info("> " +self.Id+" begins TotalN/LiveN/SuccessN/ExistingN/FailN=%d/%d/%d/%d/%d" \
                   %(CaseTemplate.TotalN, CaseTemplate.LiveN, CaseTemplate.SuccessN, CaseTemplate.ExistingN, CaseTemplate.FailN))
     if not self.to_refresh():
         CaseTemplate.ExistingN += 1
         self.read()
         self.datas = self.datass[0]
         self.result = True
         pass
     else:    
         rst = self.underlying()
         if rst == True:
             CaseTemplate.SuccessN += 1
             self.result = True
             self.get_data()
             if not self.is_refresh:
                 self.write()
         else:
             log.error(self.Id+" return error" )
             if os.path.exists(self.cacheout):
                 os.remove(self.cacheout)
             CaseTemplate.FailN += 1
             self.result = False
             
     CaseTemplate.LiveN -= 1
     log.info("< " +self.Id+" ends TotalN/LiveN/SuccessN/ExistingN/FailN=%d/%d/%d/%d/%d" \
                   %(CaseTemplate.TotalN, CaseTemplate.LiveN, CaseTemplate.SuccessN, CaseTemplate.ExistingN, CaseTemplate.FailN))
Пример #10
0
 def POST(self):
     web.header("Content-Type","text/html; charset=utf-8")
     form = forms.group_add_form()
     if not form.validates(): 
         return render("baseform.html",form=form,title="新增用户组",action="/group/add")    
     else:
         db = get_db()
         if db.query(models.RadGroup)\
              .filter(models.RadGroup.node_id == form.d.node_id)\
              .filter(models.RadGroup.group_id == form.d.group_id)\
              .count()>0:
             return errorpage("用户组编码重复")       
         try:
             group = models.RadGroup()
             group.node_id = form.d.node_id
             group.group_id = form.d.group_id
             group.group_name = form.d.group_name
             db.add(group)
             db.commit()
             db.flush()
         except Exception,e:
             db.rollback()
             log.error("add group error: %s"%str(e))
             return errorpage("新增用户组失败 %s"%str(e))
         raise web.seeother("/group",absolute=True)
Пример #11
0
 def POST(self):
     web.header("Content-Type", "text/html; charset=utf-8")
     form = forms.group_add_form()
     if not form.validates():
         return render("baseform.html",
                       form=form,
                       title="新增用户组",
                       action="/group/add")
     else:
         db = get_db()
         if db.query(models.RadGroup)\
              .filter(models.RadGroup.node_id == form.d.node_id)\
              .filter(models.RadGroup.group_id == form.d.group_id)\
              .count()>0:
             return errorpage("用户组编码重复")
         try:
             group = models.RadGroup()
             group.node_id = form.d.node_id
             group.group_id = form.d.group_id
             group.group_name = form.d.group_name
             db.add(group)
             db.commit()
             db.flush()
         except Exception, e:
             db.rollback()
             log.error("add group error: %s" % str(e))
             return errorpage("新增用户组失败 %s" % str(e))
         raise web.seeother("/group", absolute=True)
Пример #12
0
    def super_sign(self):
        follow_list = self.resolve_data()
        if not follow_list:
            log.info('取消微博超话签到')
            return
        for follow in follow_list:
            lv = f'[Lv.{follow["lv"]}]'
            name = follow['title_sub']
            log.info(f'准备为 {name} 超话签到...')
            sleep(5)
            if follow['is_sign'] == '已签':
                log.info(f'👀 {lv}{name}: 已经签到过了哦')
                continue
            elif follow['is_sign'] == '签到':
                url = follow['sign_url']
                try:
                    response = req.to_python(
                        req.request('post', url,
                                    headers=self.get_header()).text)
                except Exception as e:
                    log.error(e)
                else:
                    if response['ok'] == 1:
                        log.info(f'🥳 {lv}{name}: 签到成功')
                    else:
                        log.info(f'😳 {lv}{name}: 签到失败\n{response}')

        log.info('微博超话签到完毕')
        return
Пример #13
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} 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
Пример #14
0
    def upcall(self, kind, upcallInfo):
        if kind == pyndn.UPCALL_FINAL:#handler is about to be deregistered
            
            #if self.status and not self.is_all:    
                #self.handle.setRunTimeout(DEFAULT_NDN_RUN_TIMEOUT)
                #log.error("handler is about to be deregistered, reset it." )    
            
            return pyndn.RESULT_OK

        
        if kind in [pyndn.UPCALL_INTEREST, pyndn.UPCALL_CONSUMED_INTEREST]:
            log.error("unexpected kind: %s" %kind)
            return pyndn.RESULT_OK
        

        
        self.log_upcall_events(kind, upcallInfo)
                    
        if kind == pyndn.UPCALL_INTEREST_TIMED_OUT:
            self.do_meet_accident(kind, upcallInfo)
 
            return pyndn.RESULT_OK
        
        if kind in [pyndn.UPCALL_CONTENT_UNVERIFIED, pyndn.UPCALL_CONTENT_BAD]:
            self.do_meet_accident(kind, upcallInfo)
            return pyndn.RESULT_OK
        

        
        assert kind == pyndn.UPCALL_CONTENT, "kind: "+str(kind)
        
        self.do_receive_content(kind, upcallInfo)
        
        
        return pyndn.RESULT_OK
Пример #15
0
    def upcall(self, kind, upcallInfo):
        if kind == pyndn.UPCALL_FINAL:#handler is about to be deregistered    
            return pyndn.RESULT_OK

        
        if kind in [pyndn.UPCALL_INTEREST, pyndn.UPCALL_CONSUMED_INTEREST, pyndn.UPCALL_CONTENT_UNVERIFIED, pyndn.UPCALL_CONTENT_BAD]:
            log.error("unexpected kind: %s" %kind)
            return pyndn.RESULT_OK
        
        if kind == pyndn.UPCALL_CONTENT:
            self.is_all = True
            log.info("get data back: %s" %(upcallInfo.Interest.name))
            self.stop()
            return pyndn.RESULT_OK
        elif kind == pyndn.UPCALL_INTEREST_TIMED_OUT:
            if self.turn == -1:
                return pyndn.RESULT_REEXPRESS
            else:
                if self.ist_sentN < self.turn:
                    log.debug("timeout: %s" %(upcallInfo.Interest.name))
                    self.ist_sentN += 1
                    return pyndn.RESULT_REEXPRESS
                else:
                    log.info("CANNOT get data back after %d trials: %s" %(self.turn, upcallInfo.Interest.name))
                    self.stop()
                    return pyndn.RESULT_OK
Пример #16
0
 def run(self):
     """ run the case, after running, the statstical result is held in self.data as list
     """
     #CaseTemplate.LiveN += 1
     log.info("> " +self.Id+" begins TotalN/LiveN/SuccessN/ExistingN/FailN=%d/%d/%d/%d/%d" \
                   %(CaseTemplate.TotalN, CaseTemplate.LiveN, CaseTemplate.SuccessN, CaseTemplate.ExistingN, CaseTemplate.FailN))
     if not self.to_refresh():
         CaseTemplate.ExistingN += 1
         self.read()
         self.datas = self.datass[0]
         self.result = True
         pass
     else:    
         rst = self.underlying()
         if rst == True:
             CaseTemplate.SuccessN += 1
             self.result = True
             self.get_data()
             if not self.is_refresh:
                 self.write()
         else:
             log.error(self.Id+" return error" )
             if os.path.exists(self.cacheout):
                 os.remove(self.cacheout)
             CaseTemplate.FailN += 1
             self.result = False
             
     CaseTemplate.LiveN -= 1
     log.info("< " +self.Id+" ends TotalN/LiveN/SuccessN/ExistingN/FailN=%d/%d/%d/%d/%d" \
                   %(CaseTemplate.TotalN, CaseTemplate.LiveN, CaseTemplate.SuccessN, CaseTemplate.ExistingN, CaseTemplate.FailN))
Пример #17
0
def main_handler(event, context):
    log.info('任务开始')
    notify = Notify()
    msg_list = []
    ret = success_num = fail_num = 0
    # ============= miHoYo BBS COOKIE ============
    # 此处填米游社的COOKIE
    # 注: Github Actions用户请到Settings->Secrets里设置,Name=COOKIE,Value=<获取的值>
    # 多个账号的COOKIE值之间用 # 号隔开,例如: 1#2#3#4
    COOKIE = ''

    if os.environ.get('COOKIE', '') != '':
        COOKIE = os.environ['COOKIE']

    cookie_list = COOKIE.split('#')
    log.info(f'检测到共配置了 {len(cookie_list)} 个帐号')
    for i in range(len(cookie_list)):
        log.info(f'准备为 NO.{i + 1} 账号签到...')
        try:
            msg = f'	NO.{i + 1} 账号:{Sign(cookie_list[i]).run()}'
            msg_list.append(msg)
            success_num = success_num + 1
        except Exception as e:
            msg = f'	NO.{i + 1} 账号:\n    {e}'
            msg_list.append(msg)
            fail_num = fail_num + 1
            log.error(msg)
            ret = -1
        continue
    notify.send(status=f'成功: {success_num} | 失败: {fail_num}', msg=msg_list)
    if ret != 0:
        log.error('异常退出')
        exit(ret)
    log.info('任务结束')
Пример #18
0
    def POST(self, none):
        web.header("Content-Type", "text/html; charset=utf-8")
        form = forms.product_update_form()
        if not form.validates():
            return render("baseform.html",
                          form=form,
                          title="修改产品套餐",
                          action="/product/update/")
        else:
            db = get_db()
            product = db.query(models.RadProduct).get(form.d.id)
            if not product:
                return errorpage("产品不存在")
            try:
                product.name = form.d.name
                product.fee_num = form.d.fee_num
                product.fee_price = int(Decimal(form.d.fee_price) * 100)
                product.concur_number = form.d.concur_number
                product.bind_mac = form.d.bind_mac
                product.bind_vlan = form.d.bind_vlan
                product.bandwidth_code = form.d.bandwidth_code
                product.input_max_limit = form.d.input_max_limit
                product.output_max_limit = form.d.output_max_limit
                product.input_rate_code = form.d.input_rate_code
                product.output_rate_code = form.d.output_rate_code
                product.domain_code = form.d.domain_code
                product.status = 0
                db.commit()
                db.flush()
            except Exception, e:
                db.rollback()
                log.error("update product error: %s" % str(e))
                return errorpage("修改套餐失败 %s" % str(e))

            raise web.seeother("/product", absolute=True)
Пример #19
0
    def resolve_data(self):
        super_list = self.get_super_list()
        if not super_list:
            log.info('取消解析数据信息')
            return
        log.info('准备解析数据信息...')
        follow_list = []
        try:
            card_group = super_list['data']['cards'][0]['card_group'][1:-1]
        except Exception as e:
            log.error(e)
        else:
            for card in card_group:
                follow = {
                    'title_sub': card['title_sub'],
                    'containerid': card['scheme'].split('&')[0].split('=')[1],
                    'lv': int(re.findall('\d+', card['desc1'])[0]),
                    'is_sign': card['buttons'][0]['name'],
                    'sign_url': False
                }
                scheme = card['buttons'][0]['scheme']
                if scheme:
                    follow['sign_url'] = f'https://m.weibo.cn{scheme}'
                follow_list.append(follow)
        log.info(f'解析到 {len(follow_list)} 条数据')
        if follow_list:
            for follow in follow_list:
                log.info(f'⚜️ [Lv.{follow["lv"]}]{follow["title_sub"]}')

        log.info('数据信息解析完毕')
        return follow_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
Пример #21
0
def create_super(user,password):
    try:
        encryptuser = encrypt(password)
        db.user.insert({'role':'superadmin','name':user,'passwd':encryptuser})
        log.info("create superuser success")
        return True
    except Exception,e:
        traceback.print_exc()
        log.error("create superuser error")
        return False
Пример #22
0
    def get_awards(self):
        response = dict()
        try:
            content = requests.Session().get(CONFIG.AWARD_URL,
                                             headers=self.get_header()).text
            response = self.to_python(content)
        except json.JSONDecodeError as e:
            log.error(e)

        return response
Пример #23
0
def signalHandler(signum, frame, server):
    log.info("Recv Signal - %s" % signum)
    try:
        if server.running:
            log.error("!!!!!! STOP")
            server.stop()
        else:
            log.error("!!!!!! KILL")
            gevent.kill(server)
    except Exception, e:
        pass
Пример #24
0
 def re_express_interest(self, chunkinfo):
     if self.status == Controller.STATUS_OFF or self.status == Controller.STATUS_STEP_OFF:
         return
     
     if self.mydata.final_byte !=None and chunkinfo.begin_byte >= self.mydata.final_byte: #suppress the illegal reuqest 
         log.debug("illegel request, do not re-express it: %s" %(chunkinfo.ndn_name))
     elif self.is_all:#shouldn't happen, since already check before re-expressing
         log.error("already get all the requests, do not re-express it: %s" %(chunkinfo.ndn_name))
     else:
         self.window.update_express(chunkinfo)
         self.chunkSizeEstimator.get_optimal_data_size()
         self.express_interest(chunkinfo)
Пример #25
0
 def GET(self,nasid):
     if nasid:
         db = get_db()
         try:
             for nas in db.query(models.RadNas).filter(models.RadNas.id == nasid):
                 db.delete(nas)
             db.commit()
             db.flush()
         except Exception,e:
             db.rollback()
             log.error("delete nas error: %s"%str(e))
             return errorpage("删除失败 %s"%str(e))
Пример #26
0
 def worker():
     db = BaseDB()
     while q.qsize():
         novel = q.get()
         try:
             if ready_work(novel, db):
                 notify_page(novel[0], "start")
                 do_work(novel, db)
         except Exception, e:
             log.error("%s: %s" % (novel[0], traceback.format_exc()))
             db.modify_status(novel[0], 4)
         db.commit()
         q.task_done()
Пример #27
0
 def worker():
     db = BaseDB()
     while q.qsize():
         novel = q.get()
         try:
             if ready_work(novel, db):
                 notify_page(novel[0], "start")
                 do_work(novel, db)
         except Exception, e:
             log.error("%s: %s" % (novel[0], traceback.format_exc()))
             db.modify_status(novel[0], 4)
         db.commit()
         q.task_done()
Пример #28
0
 def qMsg(self, text, status, desp):
     if Notify.SCKEY != '':
         push_url = "https://qmsg.zendee.cn/send/" + Notify.SCKEY
         data = '{} {}\n {}'.format(text, status, desp)
         push_data = {'msg': data}
         try:
             requests.post(push_url, data=push_data)
             log.info('QMsg酱推送成功!!!')
         except Exception as e:
             log.error('QMsg酱推送失败!!!', e)
     else:
         log.info('您未配置QMsg酱推送所需的QMSG_KEY,取消QMsg酱推送')
         pass
Пример #29
0
    async def expired(self):
        """Guessing time expired"""
        self.timer = None

        try:
            log.debug('Turn timer expired, stop turn')

            await self.broadcast(message.Stop(reason='timer'))

            self.turn.explaining.lastanswer()
            self.turn.guessing.finish()
        except Exception as e:
            log.error(f'Exception while process timer: {e}')
            log.exception()
Пример #30
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}')
Пример #31
0
 def tgBot(self, text, status, desp):
     if Notify.TG_BOT_TOKEN != '' or Notify.TG_USER_ID != '':
         url = 'https://api.telegram.org/bot{}/sendMessage'.format(
             Notify.TG_BOT_TOKEN)
         data = {
             'chat_id': Notify.TG_USER_ID,
             'text': '{} {}\n\n{}'.format(text, status, desp),
             'disable_web_page_preview': True
         }
         try:
             response = self.to_python(requests.post(url, data=data).text)
         except Exception as e:
             log.error(e)
             raise HTTPError
         else:
             if response['ok']:
                 log.info('Telegram推送成功')
             elif response['error_code'] == 400:
                 log.error('请主动给bot发送一条消息并检查接收用户ID是否正确')
             elif response['error_code'] == 401:
                 log.error('TG_BOT_TOKEN错误')
             else:
                 log.error('Telegram推送失败:\n{}'.format(response))
     else:
         log.info('您未配置Telegram推送所需的TG_BOT_TOKEN和TG_USER_ID,取消Telegram推送')
         pass
Пример #32
0
def create_super(user, password):
    try:
        encryptuser = encrypt(password)
        db.user.insert({
            'role': 'superadmin',
            'name': user,
            'passwd': encryptuser
        })
        log.info("create superuser success")
        return True
    except Exception, e:
        traceback.print_exc()
        log.error("create superuser error")
        return False
Пример #33
0
 def tgjiang(self, text, status, desp):
     if Notify.TG_JIANG_TOKEN != '':
         data = f"{text}\n{status}\n{desp}"
         url = 'https://dianbao.vercel.app/send/{}/{}'.format(
             Notify.TG_JIANG_TOKEN, parse.quote(data))
         try:
             response = self.to_python(requests.get(url).text)
             log.info("TG酱 msg: " + response["msg"])
         except Exception as e:
             log.error(e)
             raise HTTPError
     else:
         log.info('您未配置TG酱推送所需的TG_JIANG_TOKEN,取消TG酱推送')
         pass
Пример #34
0
 def GET(self):
     user_id = web.input().get("user_id")
     if user_id:
         db = get_db()
         try:
             for user in db.query(models.RadUser).filter(models.RadUser.id == user_id):
                 db.delete(user)
             db.commit()
             db.flush()
         except Exception as e:
             db.rollback()
             log.error("delete user error: %s"%str(e))
             return errorpage("删除失败")
     raise web.seeother("/user",absolute=True)
Пример #35
0
    def POST(self, none):
        web.header("Content-Type", "text/html; charset=utf-8")
        form = forms.node_update_form()
        if not form.validates(source=web.input(nas_bind=[])):
            return render("baseform.html",
                          form=form,
                          title="新增节点",
                          action="/node/update/")
        else:
            db = get_db()
            radnode = db.query(models.RadNode).filter(
                models.RadNode.id == form.d.node_id).first()
            if not radnode:
                return errorpage("节点不存在")

            try:
                radnode.id = form.d.node_id
                radnode.name = form.d.node_name
                radnode.desc = form.d.node_desc

                radopr = db.query(models.RadOpr)\
                .filter(models.RadOpr.type==1)\
                .filter(models.RadOpr.node_id == form.d.node_id).first()
                radopr.node_id = radnode.id
                radopr.id = nextid()
                radopr.type = 1
                radopr.name = form.d.opr_name
                radopr.ip_addr = form.d.opr_ip
                radopr.password = encrypt(form.d.opr_passwd)
                radopr.status = 0

                #修改nas绑定
                for nasnode in db.query(models.RadNasNode).filter(
                        models.RadNasNode.node_id == radnode.id):
                    db.delete(nasnode)

                for ip in form.d.nas_bind:
                    radnasnode = models.RadNasNode()
                    radnasnode.node_id = radnode.id
                    radnasnode.ip_addr = ip
                    db.add(radnasnode)

                db.commit()
                db.flush()
            except Exception, e:
                db.rollback()
                log.error("update node error: %s" % str(e))
                return errorpage("节点修改失败 %s" % str(e))
            raise web.seeother("/node", absolute=True)
Пример #36
0
 def GET(self):
     user_id = web.input().get("user_id")
     if user_id:
         db = get_db()
         try:
             for user in db.query(
                     models.RadUser).filter(models.RadUser.id == user_id):
                 db.delete(user)
             db.commit()
             db.flush()
         except Exception as e:
             db.rollback()
             log.error("delete user error: %s" % str(e))
             return errorpage("删除失败")
     raise web.seeother("/user", absolute=True)
Пример #37
0
 def GET(self,productid):
     if productid:
         db = get_db()
         try:
             if db.query(models.RadUser).filter(models.RadUser.product_id == productid).count()>0:
                 return errorpage("产品已经有用户使用,不允许删除")
             radproduct = db.query(models.RadProduct).get(productid)
             if radproduct:
                 db.delete(radproduct)                     
                 db.commit()
                 db.flush()
         except Exception,e:
             db.rollback()
             log.error("delete product error: %s"%str(e))
             return errorpage("删除失败 %s"%str(e))
Пример #38
0
def fetch_wikipedia_raw_page(year, month, day):

    wiki_url = WIKIPEDIA_PAGE_TEMPLATE.format(YYYY=year,
                                              Month=MONTHS[month],
                                              D=day)

    log.debug('GET %s', wiki_url)
    r = requests.get(wiki_url)
    try:
        r.raise_for_status()
    except:
        log.error('NOT FOUND')
        return 'NOT FOUND: ' + wiki_url

    return r.text
Пример #39
0
 def GET(self, productid):
     if productid:
         db = get_db()
         try:
             if db.query(models.RadUser).filter(
                     models.RadUser.product_id == productid).count() > 0:
                 return errorpage("产品已经有用户使用,不允许删除")
             radproduct = db.query(models.RadProduct).get(productid)
             if radproduct:
                 db.delete(radproduct)
                 db.commit()
                 db.flush()
         except Exception, e:
             db.rollback()
             log.error("delete product error: %s" % str(e))
             return errorpage("删除失败 %s" % str(e))
Пример #40
0
 def GET(self,nodeid):
     if nodeid:
         db = get_db()
         try:
             for node in db.query(models.RadNode).filter(models.RadNode.id == nodeid):
                 db.delete(node)
             for opr in db.query(models.RadOpr).filter(models.RadOpr.node_id == nodeid):
                 db.delete(opr)   
             for nasnode in db.query(models.RadNasNode).filter(models.RadNasNode.node_id == nodeid):
                 db.delete(nasnode)                     
             db.commit()
             db.flush()
         except Exception,e:
             db.rollback()
             log.error("delete node error: %s"%str(e))
             return errorpage("删除失败 %s"%str(e))
Пример #41
0
    def discordWebhook(self, text, status, desp):
        DISCORD_WEBHOOK = self.DISCORD_WEBHOOK

        if not DISCORD_WEBHOOK:
            log.info(f'Discord SKIPPED')
            return False

        webhook = DiscordWebhook(url=DISCORD_WEBHOOK)
        embed = DiscordEmbed(title=f'{text} {status}', description=desp, color='03b2f8')
        webhook.add_embed(embed)
        response = webhook.execute()
        if (response.status_code == 200):
            log.info(f'Discord SUCCESS')
        else:
            log.error(f'Discord FAILED\n{response}')
        return True
Пример #42
0
    def discordWebhook(self, text, status, desp):
        DISCORD_WEBHOOK = self.DISCORD_WEBHOOK
        if 'DISCORD_WEBHOOK' in os.environ:
            DISCORD_WEBHOOK = os.environ['DISCORD_WEBHOOK']

        if not DISCORD_WEBHOOK:
            return log.info(f'Discord 🚫')

        webhook = DiscordWebhook(url=DISCORD_WEBHOOK)
        embed = DiscordEmbed(title=f'{text} {status}', description=desp, color='03b2f8')
        webhook.add_embed(embed)
        response = webhook.execute()
        if (response.status_code == 200):
            log.info(f'Discord 🥳')
        else:
            log.error(f'Discord 😳\n{response}')
Пример #43
0
def make_data(invoice):
    data = {}
    try:
        tree = ET.parse(invoice).getroot()
        version = tree.attrib['version']
        node = tree.find('{}Emisor'.format(PRE[version]))
        data['total'] = tree.attrib['total']
        data['emisor_rfc'] = node.attrib['rfc']
        node = tree.find('{}Receptor'.format(PRE[version]))
        data['receptor_rfc'] = node.attrib['rfc']
        node = tree.find('{}Complemento/{}TimbreFiscalDigital'.format(PRE[version], PRE['TIMBRE']))
        data['uuid'] = node.attrib['UUID']
        return data
    except Exception as e:
        log.error('La factura no se pudo parsear, asegurate de que sea un CFDI válido')
        log.debug(e)
        return {}
Пример #44
0
 def GET(self):
     node_id = web.input().get("node_id")
     group_id = web.input().get("group_id")
     if node_id and group_id:
         db = get_db()
         try:
             for group in db.query(models.RadGroup)\
              .filter(models.RadGroup.node_id == node_id)\
              .filter(models.RadGroup.group_id == group_id):
                 db.delete(group)
             db.commit()
             db.flush()
         except Exception as e:
             db.rollback()
             log.error("delete group error: %s"%str(e))
             return errorpage("删除失败")
     raise web.seeother("/group",absolute=True)                
Пример #45
0
 def iGot(self, text, status, desp):
     if Notify.IGOT_KEY != '':
         url = 'https://push.hellyw.com/{}'.format(Notify.IGOT_KEY)
         data = {'title': '{} {}'.format(text, status), 'content': desp}
         try:
             response = self.to_python(requests.post(url, data=data).text)
         except Exception as e:
             log.error(e)
             raise HTTPError
         else:
             if response['ret'] == 0:
                 log.info('iGot推送成功')
             else:
                 log.error('iGot推送失败:\n{}'.format(response))
     else:
         log.info('您未配置iGot推送所需的IGOT_KEY,取消iGot推送')
         pass
Пример #46
0
    def POST(self):
        web.header("Content-Type","text/html; charset=utf-8")
        form = forms.node_add_form()
       
        if not form.validates(source=web.input(nas_bind=[])): 
            return render("baseform.html",form=form,title="新增节点",action="/node/add")   
        else:
            db = get_db()
            if db.query(models.RadNode).filter(models.RadNode.id == form.d.node_id).count()>0:
                return errorpage("节点编号重复")
            try:
                radnode = models.RadNode()
                radnode.id = form.d.node_id
                radnode.name = form.d.node_name
                radnode.desc = form.d.node_desc

                radopr = models.RadOpr()
                radopr.node_id = radnode.id
                radopr.id = nextid()
                radopr.type = 1
                radopr.name = form.d.opr_name
                radopr.ip_addr = form.d.opr_ip
                radopr.password = encrypt(form.d.opr_passwd)
                radopr.status = 0

                db.add(radnode)
                db.add(radopr)


                #新增nas绑定
                for ip in form.d.nas_bind:
                    radnasnode = models.RadNasNode()
                    radnasnode.node_id = radnode.id
                    radnasnode.ip_addr = ip
                    db.add(radnasnode) 

                db.commit()
                db.flush()
            except Exception,e:
                db.rollback()
                log.error("add node error: %s"%str(e))
                return errorpage("节点新增失败 %s"%str(e))

            raise web.seeother("/node",absolute=True)
Пример #47
0
 def POST(self):
     web.header("Content-Type","text/html; charset=utf-8")
     form = forms.user_add_form()
     if not form.validates(): 
         form.group_id.args = getGroupIds(form.d.node_id)
         return render("baseform.html",form=form,title="新增用户",action="/user/add")    
     else:
         db = get_db()
         if db.query(models.RadUser)\
              .filter(models.RadUser.user_name == form.d.user_name)\
              .count()>0:
             return errorpage("帐号重复")       
         try:
             user = models.RadUser()
             user.id = nextid()
             user.node_id = form.d.node_id
             user.group_id = form.d.group_id
             user.user_name = form.d.user_name
             user.user_cname = form.d.user_cname
             user.password = encrypt(form.d.password)
             user.product_id = form.d.product_id
             user.status = form.d.status
             user.auth_begin_date = form.d.auth_begin_date
             user.auth_end_date = form.d.auth_end_date
             user.user_control = form.d.user_control
             user.concur_number = form.d.concur_number
             user.user_vlan = form.d.user_vlan
             user.user_mac = form.d.user_mac
             user.ip_addr = form.d.ip_addr
             user.install_address = form.d.install_address
             user.balance = 0
             user.time_length = 0
             user.basic_fee = 0
             user.create_time = currtime()
             db.add(user)
             db.commit()
             db.flush()
         except Exception,e:
             db.rollback()
             log.error("add user error: %s"%str(e))
             return errorpage("新增用户失败 %s"%str(e))
         raise web.seeother("/user",absolute=True)
Пример #48
0
 def POST(self,none):
     web.header("Content-Type","text/html; charset=utf-8")
     form = forms.nas_update_form()
     if not form.validates(): 
         return render("baseform.html",form=form,title="修改NAS设备",action="/nas/update/")    
     else:
         db = get_db()
         nas = db.query(models.RadNas).get(form.d.id)
         if not nas:
             return errorpage("Nas不存在")       
         try:
             nas.name = form.d.name
             nas.auth_secret = form.d.auth_secret
             nas.acct_secret = form.d.acct_secret
             nas.vendor_id = form.d.vendor_id
             nas.time_type = form.d.time_type
             nas.status = form.d.status
             db.commit()
             db.flush()
         except Exception,e:
             db.rollback()
             log.error("update nas error: %s"%str(e))
             return errorpage("修改Nas失败 %s"%str(e))
         raise web.seeother("/nas",absolute=True)
Пример #49
0
 def do_meet_accident(self, kind, upcallInfo):
     name = str(upcallInfo.Interest.name)
     if not name in self.mydata.unsatisfied_chunks_keyed_by_name:
         #since it's not possible that two same Interest on the fly at the same time, it sholdn't happen 
         log.error("timeout Interest not in the unsatisfied list, it should not happend: %s!!" %(name))
         return
     
     chunkinfo = self.mydata.unsatisfied_chunks_keyed_by_name[name]
     self.chunkSizeEstimator.update_loss(chunkinfo)
     self.window.update_loss(chunkinfo)
     
     if kind == 4:
         log.debug("timeout, Interest=%s, out packet: %d" \
                   %(upcallInfo.Interest.name, self.window.packet_on_the_fly))
         #log.warn("%s" %(upcallInfo))
     else:
         log.warn("-----------------strange accident: kind=%s, Interest=%s------------------" %(kind, upcallInfo.Interest.name))
         
     #window check here
     if self.window.packet_on_the_fly < self.window.get_cwnd():
         #it's already make sure that the chunk is not satisfied yet, but it could be illegal
         self.re_express_interest(chunkinfo)
     else:
         chunkinfo.status = 0 #wait for re-expressing
Пример #50
0
def main():
    log.info("------------------------------------------------------------")
    session = Session()
    (options, args) = parser.parse_args()
    if options.filename is not None:
        feeds = [options.filename]
    else:
        feeds = settings.get('main', 'feeds').split()
    preferred_quality = settings.get('main', 'preferred_quality')
    if settings.has_option('main', 'global_exclude_regex'):
        exclude_regex = re.compile(settings.get('main', 'global_exclude_regex'))
    else:
        exclude_regex = None

    for feed_url in feeds:
        feed = parse(feed_url)
        log.info("Checking %s" % feed['feed']['subtitle'])
        for entry in feed.entries:
            if (exclude_regex is not None and
                exclude_regex.search(entry.description.lower()) is not None):
                log.info("SKIP %s" % entry.description)
                continue
            data = extract_metadata(entry.description)
            try:
                data['torrent_url'] = entry.enclosures[0]['href']
            except (IndexError, KeyError):
                log.warning("No torrent found for %(name)s" % data)
            show = TVShow(**data)
            existing_qualities = session.query(TVShow).filter(TVShow.name==show.name).\
                filter(TVShow.season==show.season).\
                filter(TVShow.episode==show.episode)
            preferred_qualities = existing_qualities.\
                filter(TVShow.quality==preferred_quality)

            # nothing yet? then add unconditionally
            if existing_qualities.count()==0:
                session.add(show)
                log.info("ADDED %(name)s %(season)s %(episode)s in %(quality)s" % show.__dict__)
            # already in preferred quality?
            elif preferred_qualities.count() > 0:
                log.info("HAVE %(name)s %(season)s %(episode)s to %(quality)s" % show.__dict__)
                continue
            # update existing quality with this one:
            else:
                existing_quality = existing_qualities.one()
                if show.quality != existing_quality.quality:
                    session.delete(existing_quality)
                    session.add(show)
                    log.info("UPDATED %(name)s %(season)s %(episode)s to %(quality)s" % show.__dict__)
    
    torrent_download_dir = path.expanduser(settings.get('main', 'torrent_download_dir'))
    shows = session.query(TVShow).filter(TVShow.status==u'new')
    if shows.count() > 0:
        log.info("downloading torrents to %s" % torrent_download_dir)
        for show in session.query(TVShow).filter(TVShow.status==u'new'):
            torrent_path, result = urlretrieve(show.torrent_url, path.join(torrent_download_dir,
                "%s.torrent" % show.filename))
            if result.type == 'application/x-bittorrent':
                show.status = u'torrent_downloaded'
                log.info("DOWNLOAD %(name)s %(season)s %(episode)s in %(quality)s" % show.__dict__)
            else:
                log.error("Couldn't download %s" % show.torrent_url)
    else:
        log.info("no shows to download")

    session.commit()
Пример #51
0
    log.info("Start Henem Server, environment - %s" % settings.environment)

    bindAddr = config.get("main", "bind")
    bindPort = config.getint("main", "port")

    log.info("bind server - %s:%s" % (bindAddr, bindPort))

    cherrypy.tools.allow = cherrypy.Tool("on_start_resource", http_methods_allowed)
    cherrypy.server.bind_addr = (bindAddr, bindPort)

    log.info("Start server...")
    server.start()

    try:
        cherrypy.tree.mount(ManagementInterface(server), "/henem")
        cherrypy.engine.start()
        server.join()
    except KeyboardInterrupt, e:
        log.info("KEYBOARD INTERRUPT!!!!!!")
    except Exception, e:
        log.error(e)

    log.info("Waiting for server stop.")
    cherrypy.engine.stop()

    if server.running:
        server.stop()
    server.join(3)

    log.info("Stop server - %s" % datetime.datetime.now())
Пример #52
0
 def prepare(self, upcallInfo):
     ist = upcallInfo.Interest
     ist_name = ist.name
     
     flag_index = None #len(ist_name) - 2 #index of the end component
     
     for i in range(len(ist_name)-2):
         sub = ist_name[i]
         if sub == ADAPTIVE_MOD_FLAG:
             flag_index = i
             break
     
     if flag_index == None:
         log.error("not a flow consumer's interest, ignore: %s" %(ist_name))
         return None
     
     expected_data_size = int(ist_name[flag_index+1])
     begin_byte = int(ist_name[flag_index+2])
     name = ist_name[:flag_index] #not include the flag
     
     
     name_str = str(name)
     
     if name_str in self.readers:
         reader = self.readers[name_str]
         log.debug("%s in reader" %(name_str))
     else:
         if self.is_dir:
             subpath = ist_name[upcallInfo.matchedComps:flag_index]
             fpath = self.path
             for i in range(upcallInfo.matchedComps, flag_index):
                 temp = ist_name[i]
                 fpath = os.path.join(fpath, temp)
             #assume that matchedComps is the number of matched components, not index
             
             if not os.path.exists(fpath):
                 log.critical("path %s from Interest %s does not exist" %(fpath, ist_name))
                 return None
             if os.path.isdir(fpath):
                 log.critical("path %s from Interest %s is not a file" %(fpath, ist_name))
                 return None
             
         else:#not serve all the directory
             if upcallInfo.matchedComps != flag_index:
                 log.critical("umatched ndn_name: %s, %s"%(ist_name, self.ndn_name))
                 return None
             else:
                 fpath = self.path
                 
         reader = Reader(fpath=fpath)
         self.readers[name_str] = reader
         log.debug("add a new reader: %s" %(name_str))
     data = reader.read(begin_byte, expected_data_size)
     
     if data == None:
         log.critical("Interest %s: begin_byte %s > file_size %s" %(ist_name, begin_byte, reader.fsize))
         nack = self._nack_template(ist_name, reader)
         return nack
     else:
         log.info("Interest: %s, expected_data_size: %s, begin_byte: %s, data_size: %s" \
                   %(ist.name, expected_data_size, begin_byte, len(data)))
                     
         co = self._data_template(ist_name, data, reader.fsize, pyndn.CONTENT_DATA)
         
         return co