Example #1
0
 def handleRootPage(self):
     self._writeheaders()
     
     styles = ''
     scripts = ''
     
     styleTpl = '<link rel="stylesheet" href="$$">\n'
     scriptTpl = '<script src="$$"></script>\n'
     
     for root, dirs, files in os.walk('widgets'):
         for file in files:
             if file.endswith('.css'):
                 styles += styleTpl.replace('$$', root+os.sep+file)
             if file.endswith('.js'):
                 scripts += scriptTpl.replace('$$', root+os.sep+file)
     
     f = open('core/static/index.html').read()
     f = f.replace('{{styles}}',styles)
     f = f.replace('{{scripts}}',scripts)
     
     f = f.replace('{{core}}',
                   str(Config().getNamespace('core',True)))
     f = f.replace('{{widgets}}',
                   str(Config().getNamespace('widgets',True)))
     self.wfile.write(f)
Example #2
0
    async def post(self):
        username = self.post_data.get('username', '')
        password = self.post_data.get('password', '')
        try:
            libs.validator.username(username)
            libs.validator.password(password)
        except libs.validator.ValidationError as e:
            self.send_to_client(-1, message=e.__str__())
            return
        if username == Config().password_login.get(
                'username') and password == Config().password_login.get(
                    'password'):
            pb_account = await AccountServer().get_account_by_id(
                account_id=int(Config().password_login.get('account_id')),
                app_id=self.app_id_int64,
                request_id=self.request_id)

            account = Account(pb_account)
            # get account userinfo
            if account.status == pbaccount_pb2.STATUS_ACTIVATED:
                pb_userinfo = await AccountServer().get_userinfo(
                    account.account_id,
                    app_id=self.app_id_int64,
                    request_id=self.request_id)
                await account.set_userinfo(pb_userinfo)
                self.send_to_client(0, message='登陆成功', response=account.dump())
            else:
                self.send_to_client(-1, message='登录状态异常')

        else:
            self.send_to_client(-1, message='账号或密码错误')
Example #3
0
    async def post(self):
        co_id = self.post_data.get('co_id', None)
        category = self.post_data.get('category', None)
        try:
            libs.validator.required(co_id, 'co_id')
            libs.validator.choices(category, ['sr', 'ic'], 'category')
        except libs.validator.ValidationError as e:
            self.send_to_client_non_encrypt(400, message=e.__str__())
            return
        logging.info('{}_{}: IrFit'.format(category, co_id))

        interval = Config().image_retrieval.get('fit_interval')
        time_format = Config().time_format
        fit_status = my_redis.redis_hgetall(category, co_id)
        if len(fit_status) > 0:
            fstatus = fit_status.get('status')
            if fstatus in ['queuing', 'fitting']:
                self.send_to_client_non_encrypt(202,
                                                'success',
                                                response='请求已接受,请勿重复提交')
                return
            etime = time.strptime(fit_status.get('etime'), time_format)
            if fstatus == 'finished' and time.time() - time.mktime(
                    etime) < interval:
                self.send_to_client_non_encrypt(403,
                                                'failure',
                                                response='请求过于频繁,请稍后再试')
                return

        co_info = my_redis.redis_lpush('ir', category, co_id)
        my_redis.redis_hset(category, co_id, 'status', 'queuing')
        self.send_to_client_non_encrypt(202, 'success', response='请求已接受')
Example #4
0
def ob_sn_parallel(order_src, sku_bin, sku_vol_prior, second_qty, min_batch,
                   max_bin_area):
    t1 = time.time()
    heap_qty_list = Config().sn.get('heap_qty')
    cores = min(Config().sn.get('fit_workers'), len(heap_qty_list))
    process_pool = Pool(cores)
    process_list = []
    for i in range(cores):
        p = process_pool.apply_async(ob_sn,
                                     args=(order_src, sku_bin, sku_vol_prior,
                                           second_qty, min_batch, max_bin_area,
                                           heap_qty_list[i]))
        process_list.append(p)
    process_pool.close()
    process_pool.join()
    max_batch_qty, max_heap_qty, max_covered, max_batch_sn, max_second_sn, max_bin_sn = None, None, \
        -1, None, None, None
    for v in process_list:
        batch_qty, heap_qty, covered, batch_sn, second_sn, bin_sn = v.get()
        if max_covered < covered or (max_covered == covered
                                     and batch_qty < max_batch_qty):
            max_batch_qty = batch_qty
            max_heap_qty = heap_qty
            max_covered = covered
            max_batch_sn = batch_sn
            max_second_sn = second_sn
            max_bin_sn = bin_sn

    logging.info(
        'ob_sn_parallel time:{:.2f}s cores:{} batch_qty:{} max_heap_qty:{} max_covered:{} total:{} heap_qty_list:{}'
        .format(time.time() - t1, cores, max_batch_qty, max_heap_qty,
                max_covered, len(order_src), heap_qty_list))
    return max_covered, max_batch_sn, max_second_sn, max_bin_sn
Example #5
0
 def __init__(self):
     self.__cfgReporting = Config(os.path.join(RAGPICKER_ROOT, 'config', 'reporting.conf'))
     self.__cfgProcessing = Config(os.path.join(RAGPICKER_ROOT, 'config', 'processing.conf'))
     self.__mongodbEnabled = self.__cfgReporting.getOption("mongodb", "enabled")
     self.__codedbEnabled = self.__cfgReporting.getOption("codeDB", "enabled")
     self.__bluecoatEnabled = self.__cfgProcessing.getOption("all_bluecoatMalwareAnalysisAppliance", "enabled")
     
     if self.__mongodbEnabled:
         #Anbindung an Datenbank MongoDB Collection Ragpicker herstellen
         try:
             mongodbHost = self.__cfgReporting.getOption("mongodb", "host")
             mongodbPort = self.__cfgReporting.getOption("mongodb", "port")
             self.__mongodbConnection = MongoClient(mongodbHost, mongodbPort)
             self.__mongodbCollectionRagpicker = self.__mongodbConnection.MalwareAnalyse.ragpicker
             self.__mongodbCollectionFamilies = self.__mongodbConnection.MalwareAnalyse.families
             self.__mongodbCollectionSandboxTaskQueue = self.__mongodbConnection.MalwareAnalyse.sandboxTaskQueue
         except TypeError:
             raise Exception("MongoDB connection port in report.config must be integer")
         except ConnectionFailure:
             raise Exception("Cannot connect to MongoDB (ragpicker)")
     
     if self.__codedbEnabled:
         #Anbindung an Datenbank MongoDB Collection CodeDB herstellen
         try:
             codedbHost = self.__cfgReporting.getOption("codeDB", "mongo_db_host")
             codedbPort = self.__cfgReporting.getOption("codeDB", "mongo_db_port")
             self.__codedbConnection = MongoClient(codedbHost, codedbPort)
             self.__codedbCollectionCodedb = self.__codedbConnection.MalwareAnalyse.codeDB
         except TypeError:
             raise Exception("MongoDB connection port for CodeDB in report.config must be integer")
         except ConnectionFailure:
             raise Exception("Cannot connect to MongoDB (codeDB)")  
Example #6
0
def init_options():
    options.define("debug", default=Config().debug)
    options.define("thread", default=Config().thread)
    options.define('port',
                   default=Config().port,
                   help='run on the given port',
                   type=int)
Example #7
0
def init():
    global oss_bucket
    oss_bucket = create(
        Config().oss["access_id"],
        Config().oss["access_secret"],
        Config().oss["bucket"],
        Config().oss["endpoint"],
    )
    def __init__(self):
        self.session = Request()
        sys_str = platform.system()

        # 驱动路径
        if sys_str == "Windows":
            path = Config().CHROME_DRIVER_WIN_PATH
        elif sys_str == "Linux":
            path = Config().CHROME_DRIVER_MAC_PATH
        else:
            path = Config().CHROME_DRIVER_MAC_PATH
Example #9
0
 def delete_config(self, event):
     cfg = Config()
     row = self.list_config.GetSelectedRow()
     if row is not wx.NOT_FOUND:
         idx = int(self.list_config.GetTextValue(row, 0))
         conf = self.config
         self.config = {'db': conf}
         del self.config['db'][idx]
         cfg.set(self.config)
     cfg = Config()
     self.config = cfg.get('db')
     self.dict2list()
Example #10
0
    async def post(self):
        code = self.post_data.get('code', None)
        if not code:
            raise HTTPError(400, "code为空?", reason="code为空?")

        # login to fetch openid/session_key/unionid
        login_response = await WxCCServer().miniprogram_login(
            code, self.request_id)
        if login_response is None:
            raise HTTPError(500, "登录微信服务器出错", reason="登录微信服务器出错")

        # get account
        exists_wechat = await AccountServer().exists_partner_wechat(
            identifier=login_response.unionid,
            app_id=self.app_id_int64,
            request_id=self.request_id)

        if not exists_wechat:
            # create account
            pb_account = await AccountServer().create_account_by_partner(
                partner=pbaccount_pb2.PARTNER_WECHAT,
                identifier=login_response.unionid,
                origin_data={},
                app_id=self.app_id_int64,
                request_id=self.request_id)
            # 分配空间
            await MembershipServer().set_total_storage_change(
                account_id=pb_account.account_id,
                changed_value=Config().membership.get("register_default_size"),
                title=Config().membership.get("register_default_title"),
                details=Config().membership.get("register_default_details"),
                request_id=self.request_id)
        else:
            pb_account = await AccountServer().auth_partner_account(
                identifier=login_response.unionid,
                app_id=self.app_id_int64,
                request_id=self.request_id)

            # set account pair to wxcc server
        await WxCCServer().miniprogram_set_account_pair(
            account_id=pb_account.account_id,
            login_response=login_response,
            request_id=self.request_id)

        account = Account(pb_account)
        pb_userinfo = await AccountServer().get_userinfo(
            account.account_id,
            app_id=self.app_id_int64,
            request_id=self.request_id)
        await account.set_userinfo(pb_userinfo)

        self.send_to_client(0, message='登录成功', response=account.dump())
Example #11
0
    def __init__(self):
        self.session = Request()
        sys_str = platform.system()

        # 驱动路径
        if sys_str == "Windows":
            self.or_client_path = Config().ORACLE_CLIENT_WIN_PATH
        elif sys_str == "Linux":
            self.or_client_path = Config().ORACLE_CLIENT_WIN_PATH
        else:
            self.or_client_path = Config().ORACLE_CLIENT_WIN_PATH

        #  notice python 64位 instantclient-basic 64位 cx_oracle 64位
        cx_Oracle.init_oracle_client(lib_dir=self.or_client_path)
Example #12
0
    def __init__(self):
        self.session = Request()
        sys_str = platform.system()
        # 新浪 ['sina'] 腾讯 ['tencent', 'qq']
        self.quotation = easyquotation.use('sina')
        self.quotation_timekline = easyquotation.use("timekline")

        # 驱动路径
        if sys_str == "Windows":
            path = Config().CHROME_DRIVER_WIN_PATH
        elif sys_str == "Linux":
            path = Config().CHROME_DRIVER_MAC_PATH
        else:
            path = Config().CHROME_DRIVER_MAC_PATH
Example #13
0
    def prepare(self):
        # get post data
        try:
            data = json.loads(self.request.body)
            if data is not None:
                self.post_data = data
        except:
            raise HTTPError(400,
                            "request body parse error",
                            reason="request body parse error")

        # check the server state
        # server_alive, server_status_message = get_server_status("api-gw")
        # if not server_alive:
        #     raise HTTPError(504, server_status_message,
        #                     reason=server_status_message)

        if not Config().debug:
            self.app_id = self.post_data.get("app_id", None)
            if not self.app_id:
                raise HTTPError(400,
                                "app id not found",
                                reason="app id not found")

            # self.app_id_int64 = int(self.app_id, 36)
            # if not self.app_id_int64:
            #     raise HTTPError(400, "app id invalid", reason="app id invalid")

            # # get app version
            # try:
            #     ver = self.get_argument('version', '1.0')
            #     if not ver:
            #         ver = '1.0'
            #     self.app_version = V(ver)
            # except Exception as e:
            #     logging.warning('version argument error:{0}'.format(e))
            #     self.app_version = V('1.0')

            # if self.app_version < V(Config().app_version_require.get(self.app_id, '1.0.0')):
            #     raise HTTPError(400, "app version too low",
            #                     reason="app version too low")

            # get auth token
            self.token = self.post_data.get('token', None)

            # get secret
            self.secret = Config().app_key_secret.get(self.app_id, None)
            if self.secret is None:
                raise HTTPError(400, "app id invalid", reason="app id invalid")
Example #14
0
 def __init__(self):
     self.totalScore = 0  # sum of scores
     self.numberScores = 0  # number of scores entered
     self.processName = multiprocessing.current_process().name
     self.task = dict()
     self.cfgPreProcessing = Config(
         os.path.join(RAGPICKER_ROOT, 'config', 'preProcessing.conf'))
     self.cfgProcessing = Config(
         os.path.join(RAGPICKER_ROOT, 'config', 'processing.conf'))
     self.cfgReporting = Config(
         os.path.join(RAGPICKER_ROOT, 'config', 'reporting.conf'))
     self.cfgCrawler = Config(
         os.path.join(RAGPICKER_ROOT, 'config', 'crawler.conf'))
     self.database = Database()
     log.info("INIT " + self.processName)
Example #15
0
    def test_given_new_q_agent_correctly_update_q_values(self):
        config_path = '/test/qlearning_test/qagent_test.json'
        config = Config(config_path)

        qagent = QAgent(config)

        state = [1, 1]
        next_state = [1, 2]
        """
        Test ran with the following config values:
            discount_factor: 0.95,
            learning_rate: 0.8,
            random_action: 0.0
            
            current_q_value: 0
            reward: 1
            max_q_value_s1: 0

        Q-Learning Algorithm:
            q(s) + lr * (reward + df * maxq(s1) - q(s))
            (0 + 0.8 * (1  + 0.95 * 0 - 0) = 0.8
        """

        qagent.update_q_table(state, next_state, 'UP', 1)

        self.assertEqual(0.8, qagent.get_q_value(state, 'UP'))
Example #16
0
    async def post(self):
        try:
            libs.validator.space_id(self.post_data.get("space_id"))
            libs.validator.account_id(self.post_data.get("account_id"))

        except libs.validator.ValidationError as e:
            self.send_to_client(-1, message=e.__str__())
            return

        growth_list_key = 'growth_list:{}'.format(
            zbase62.decode(self.post_data.get('space_id')))
        growth_list = rd.redis_get(growth_list_key)
        growth_list = json.loads(str(growth_list,
                                     encoding="utf-8")) if isinstance(
                                         growth_list, bytes) else growth_list
        if not growth_list:
            pb_growth_list = await RecordServer().get_growth_list(
                account_id=zbase62.decode(self.post_data.get("account_id")),
                space_id=zbase62.decode(self.post_data.get('space_id')),
                creator_id=self.current_user.account_id,
                request_id=self.request_id)
            if pb_growth_list:
                growth_list = []
                for growth in pb_growth_list.growth_list:
                    growth_list.append(GrowthDetail(growth).growth_detail)
                rd.redis_set(growth_list_key, json.dumps(growth_list),
                             Config().redis.get("expire_list"))

        if growth_list is not None:
            self.send_to_client(0, message='成功获取生长记录详情', response=growth_list)
            return

        raise HTTPError(500, "get growth list failed", reason="服务器出错,请联系客服解决")
Example #17
0
 async def on_guild_join(self, guild):
     if guild.id not in self.bot.configs:
         self.bot.configs[guild] = Config(guild.id,
                                          bot=self.bot,
                                          db=self.bot.db)
         await self.bot.get_config(guild).load()
     fire = self.bot.get_guild(564052798044504084)
     desc = self.bot.get_cog('Description')
     await desc.set_desc(
         fire, f'Fire is an open-source, multi-purpose bot '
         f'with {len(self.bot.commands)} commands and is used in '
         f'{len(self.bot.guilds)} servers.')
     self.bot.logger.info(
         f'$GREENFire joined a new guild! '
         f'$CYAN{guild.name}({guild.id}) '
         f'$GREENwith $CYAN{guild.member_count} $GREENmembers')
     botlists = [
         self.bot.get_cog('TopGG'),
         self.bot.get_cog('DiscordBoats')
     ]
     for l in botlists:
         try:
             await l.post_guilds()
         except Exception as e:
             self.bot.logger.warn(
                 f'$YELLOWFailed to post guild count to $CYAN{l.__class__.__name__}',
                 exc_info=e)
Example #18
0
 def getOracleConnect_withPool(self):
     if self.oracle_pool is None:
         # 创建连接池
         self.oracle_pool = cx_Oracle.SessionPool(
             Config().ORACLE_SERVER_USERNAME,
             Config().ORACLE_SERVER_SECRET,
             Config().ORACLE_SERVER_CONNECTSTRING,
             min=2,
             max=10,
             increment=1,
             threaded=True,
             encoding="UTF-8")
         # print(self.oracle_pool.max_lifetime_session)
     t_connectObj_pool = self.oracle_pool.acquire()
     self.connCnt_pool += 1
     return t_connectObj_pool
Example #19
0
def main(keep_alive=False):
    fit_workers = Config().image_retrieval.get('fit_workers')
    for _ in range(fit_workers):
        Process(target=fit_queue, args=('sr', )).start()
        # Process(target=fit_queue, args=('ic',)).start()
    while keep_alive:
        time.sleep(10**10)
Example #20
0
    def __write_tcp_segment_verbose_output__(self, segment_data):
        '''
        Formats the terminal verbose output for the TCP segment portion of the packets
        @param (segment_data) - Contents within the segment (i.e flags, ports, etc.)
        @return None
        '''
        pk = Packet()
        cfg = Config()
        esp = Espionage()

        (segment_source_port, segment_destination_port, segment_sequence,
         segment_acknowledgment, __urg_flag__, __ack_flag__, __psh_flag__,
         __rst_flag__, __syn_flag__,
         __fin_flag__) = pk.unpack_packet(cfg.ESPI_TCP_STRUCT_SEGMENT_FORMAT,
                                          segment_data, 24)

        esp.print_espionage_noprefix("\tTCP Segment {}".format(
            cfg.ESPI_ASCII_DOWN_ARROW))
        esp.print_espionage_notab(
            "\t\tSource Port # {}, Destination Port # {}, [Sequence] {}".
            format(segment_source_port, segment_destination_port,
                   segment_sequence))
        # Write Flags
        esp.print_espionage_noprefix("\t\tTCP Segment Flags")
        esp.print_espionage_notab(
            "\t\tFLAG_URG: {}, FLAG_ACK: {}, FLAG_PSH: {}, FLAG_RST: {}".
            format(__urg_flag__, __ack_flag__, __psh_flag__, __rst_flag__))
        # SYN/FIN
        esp.print_espionage_notab("\t\tFLAG_SYN: {}, FLAG_FIN: {}".format(
            __syn_flag__, __fin_flag__))
Example #21
0
def main():
    """ Package/CLI entry point """

    # Validate config.cfg, init Config singleton
    try:
        Config("config.cfg")

    # If failure in configuration, don't even
    except Exception as e:
        print(f"Error reading config.cfg:\n\t{e}")
        exit(1)

    # Validate items in notes directory, init Book singleton
    try:
        Book()

    except Exception as e:
        print(f"Error building notes dir:\n\t{e}")
        exit(1)

    # Pass args to our CLI module and execute
    try:
        CLI(sys.argv)

    except Exception as e:
        print(f"Error executing command:\n\t{e}")
Example #22
0
    async def post(self):
        try:
            validator.msg_title(self.post_data.get('msg_title'))
            validator.word(self.post_data.get('msg_content'))
            validator.account_id(self.post_data.get('from_id'))
        except validator.ValidationError as e:
            self.send_to_client(-1, message=e.__str__())
            return
        group_message_id = await ZIDServer().generate(self.request_id)
        if group_message_id is None:
            raise HTTPError(500,
                            "zid-server generate failed",
                            reason="服务器出错,请联系客服解决")
        result = await MsgBoxServer().create_group_message(
            group_message_id=group_message_id,
            product_id=Config().product,
            msg_title=self.post_data.get("msg_title"),
            msg_content=self.post_data.get("msg_content"),
            from_id=zbase62.decode(self.post_data.get("from_id")),
            request_id=self.request_id)
        if result:
            self.send_to_client(-1, '消息发送失败!')
            return

        self.send_to_client(0, '消息发送成功!')
        return
def runCrawler():
    mapURL = {}
    cfgCrawler = Config(os.path.join(RAGPICKER_ROOT, 'config', 'crawler.conf'))

    # Build the PluginManager
    crawlerPluginManager = PluginManager()
    crawlerPluginManager.setPluginPlaces(["crawler"])
    crawlerPluginManager.collectPlugins()

    # Trigger run from the "Crawler" plugins
    for pluginInfo in sorted(crawlerPluginManager.getAllPlugins(),
                             key=lambda PluginInfo: PluginInfo.name):
        crawlerModul = pluginInfo.plugin_object

        # Config for crawler module
        try:
            options = cfgCrawler.get(pluginInfo.name)
            crawlerModul.set_options(options)
        except Exception:
            log.error("Crawler module %s not found in configuration file",
                      pluginInfo.name)

        # If the crawler module is disabled in the config, skip it.
        if not options.enabled:
            continue

        try:
            log.debug("Run Crawler: " + pluginInfo.name)
            returnMap = crawlerModul.run()
            mapURL.update(returnMap)
        except Exception as e:
            log.error('Error (%s) in %s', e, pluginInfo.name)

    return mapURL
Example #24
0
    def __process_url(self, url):
        # Crawler config load
        cfgCrawler = Config(
            os.path.join(RAGPICKER_ROOT, 'config',
                         'crawler.conf')).get("clientConfig")

        data = None
        headers = {
            'User-Agent':
            cfgCrawler.get("browser_user_agent",
                           "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"),
            'Accept-Language':
            cfgCrawler.get("browser_accept_language", "en-US"),
        }

        # Save original socket
        originalSocket = socket.socket
        # Set TOR Socks proxy
        commonutils.setTorProxy()

        request = urllib2.Request(url, data, headers)

        try:
            url_dl = urllib2.urlopen(request, timeout=30).read()
        except urllib2.HTTPError as e:
            raise e
        except urllib2.URLError as e:
            raise e
        except Exception, e:
            raise IOError("Thread(" + self.processName +
                          ") - %s - Error parsing %s" % (e, url))
Example #25
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.config = Config("config.yaml").config
     StreamHandler(sys.stdout).push_application()
     self.log = Logger("Aiko")
     self.osuapi = OsuApi(self.config["osuapi"], connector=AHConnector())
     self.kv = self.loop.run_until_complete(_connect_redis(self))
 def send_voice_code_of_yiyuan(self, phone, name='', content=''):
     """
     发送语音验证码
     购买地址 https://market.aliyun.com/products/57126001/cmapi019902.html?spm=5176.2020520132.101.5.37857218O6iJ3n
     :return:
     """
     appcode = Config().NOTIFICATION_API_APP_CODE
     if not appcode:
         CommonLog.add_quick_log(CommonLog.MESSAGE_EMPTY_APP_CODE).flush()
         return False
     body = {
         'userName': name,
         'mailNo': content
     }
     params = {
         'content': body,
         'mobile': phone,
         'sex': 2,
         'tNum': 'T170701001056'
     }
     response = self.session.request(url=API_NOTIFICATION_BY_VOICE_CODE + urllib.parse.urlencode(params),
                                     method='GET', headers={'Authorization': 'APPCODE {}'.format(appcode)})
     result = response.json()
     response_message = result.get('showapi_res_body.remark')
     if response.status_code in [400, 401, 403]:
         return CommonLog.add_quick_log(CommonLog.MESSAGE_VOICE_API_FORBID).flush()
     if response.status_code == 200 and result.get('showapi_res_body.flag'):
         CommonLog.add_quick_log(CommonLog.MESSAGE_VOICE_API_SEND_SUCCESS.format(response_message)).flush()
         return True
     else:
         return CommonLog.add_quick_log(CommonLog.MESSAGE_VOICE_API_SEND_FAIL.format(response_message)).flush()
Example #27
0
 async def on_socket_response(self, payload):
     t = payload['t']
     if t == 'GUILD_CREATE':
         guild = int(payload['d']['id'])
         if guild not in self.bot.configs:
             self.bot.configs[guild] = Config(guild, bot=self.bot, db=self.bot.db)
         if not self.bot.configs[guild].loaded:
             await self.bot.configs[guild].load()
     if not t:
         if payload['op'] == 11:
             t = 'HEARTBEAT'
         elif payload['op'] == 10:
             t = 'HELLO'  # hi
         elif payload['op'] == 9:
             t = 'INVALID_SESSION'
         elif payload['op'] == 7:
             t = 'RECONNECT'
         else:
             self.bot.logger.warn(f'$REDUnknown event, $CYAN{t}\n$REDPayload: $CYAN{payload}')
             return
     if t not in self.bot.stats['socket']:
         self.bot.logger.info(f'$GREENFound new event, $CYAN{t}')
         self.bot.stats['socket'][t] = 1
     else:
         self.bot.stats['socket'][t] += 1
 def send_voice_code_of_dingxin(self, phone, name='', info={}):
     """
     发送语音验证码 ( 鼎信 )
     购买地址 https://market.aliyun.com/products/56928004/cmapi026600.html?spm=5176.2020520132.101.2.51547218rkAXxy
     :return:
     """
     appcode = Config().NOTIFICATION_API_APP_CODE
     if not appcode:
         CommonLog.add_quick_log(CommonLog.MESSAGE_EMPTY_APP_CODE).flush()
         return False
     data = {
         'tpl_id': 'TP1901174',
         'phone': phone,
         'param': 'name:{name},job_name:{left_station}到{arrive_station}{set_type},orderno:{orderno}'.format(
             name=name, left_station=info.get('left_station'), arrive_station=info.get('arrive_station'),
             set_type=info.get('set_type'), orderno=info.get('orderno'))
     }
     response = self.session.request(url=API_NOTIFICATION_BY_VOICE_CODE_DINGXIN, method='POST', data=data,
                                     headers={'Authorization': 'APPCODE {}'.format(appcode)})
     result = response.json()
     response_message = result.get('return_code')
     if response.status_code in [400, 401, 403]:
         return CommonLog.add_quick_log(CommonLog.MESSAGE_VOICE_API_FORBID).flush()
     if response.status_code == 200 and result.get('return_code') == '00000':
         CommonLog.add_quick_log(CommonLog.MESSAGE_VOICE_API_SEND_SUCCESS.format(response_message)).flush()
         return True
     else:
         return CommonLog.add_quick_log(CommonLog.MESSAGE_VOICE_API_SEND_FAIL.format(response_message)).flush()
Example #29
0
    def __init__(self,
                 name,
                 root="wrapper-data/json",
                 encoding="default",
                 pickle=True):
        self.Data = {}
        self.name = name
        self.root = root
        self.pickle = pickle
        self.configManager = Config()
        self.configManager.loadconfig()
        self.log = logging.getLogger('Storage.py')

        if encoding == "default":
            self.encoding = self.configManager.config["General"]["encoding"]
        else:
            self.encoding = encoding

        if self.pickle:
            self.file_ext = "pkl"
        else:
            self.file_ext = "json"

        self.load()
        self.timer = time.time()
        self.abort = False

        t = threading.Thread(target=self.periodicsave, args=())
        t.daemon = True
        t.start()
Example #30
0
    async def miniprogram_decrypt_userinfo(self,
                                           account_id,
                                           raw_data,
                                           encrypted_data,
                                           signature,
                                           iv,
                                           request_id=None):
        """
        解密userinfo
        :param account_id:
        :param raw_data:
        :param encrypted_data:
        :param signature:
        :param iv:
        :param request_id:
        :return:
        """
        msg = pbwxcc_pb2.EncryptedUserinfo(
            appid=Config().wx_app_id.get("miniprogram"),
            account_id=account_id,
            raw_data=raw_data,
            encrypted_data=encrypted_data,
            signature=signature,
            iv=iv)

        return await MServer().call("wxcc-server",
                                    "MiniProgramDecryptUserInfo", msg,
                                    request_id)