Пример #1
0
 def __init__(self, conf_path='config/pn_conf.yaml', event_notify=None):
     self.conf_path = os.path.abspath(conf_path)
     self.conf = getConf(self.conf_path, root_key='tods')
     
     self.loop = None
     self.event_notify = event_notify
     self.net = NetManager(conf_path=self.conf_path, loop=self.loop, event_notify=self.event_notify)
Пример #2
0
 async def changeDomainIp(self, ip, sub_domain=''):
     assert ip
     r = await self.getRecordList(sub_domain)
     if r:
         r = r[0]
         name, updated_on, record_id, old_ip = r['name'], r[
             'updated_on'], r['id'], r['value']
         #-#            info('%s(id %s) ip %s @%s', name, record_id, old_ip, updated_on)
         if old_ip != ip:
             rtn = await self.changeRecord(record_id, ip, sub_domain)
             info('%s(id %s) ip %s -> %s res:\n%s', name, record_id, old_ip,
                  ip, pcformat(rtn))
             if sub_domain == '@':
                 try:
                     sendmail_conf = getConf('config/dn.yaml',
                                             root_key='sendmail')
                     send_mail(
                         sendmail_conf['smtp_server'],
                         sendmail_conf['smtp_port'], sendmail_conf['user'],
                         sendmail_conf['pwd'], sendmail_conf['user'],
                         (sendmail_conf['user'], ), [],
                         f'ip地址变化 {self.conf["Domain"]} {datetime.now().strftime("%Y%m%d %H:%M:%S")}',
                         f'{old_ip} --> {ip}', [])
                 except:
                     pass
         else:
             info('%s(id %s) ip not change %s', name, record_id, old_ip)
     else:
         info('no record matching sub domain %s, try to create ...',
              sub_domain)
         rtn = await self.addRecord(ip, sub_domain)
         info('%s create %s res:\n%s', sub_domain, ip, pcformat(rtn))
Пример #3
0
    def createTable(table_obj):
        conf_path = os.path.abspath('config/pn_conf.yaml')
        conf = getConf(conf_path, root_key='orm')
        conf = conf['sis']
        engine = create_engine(conf['conn_str'], echo=conf['echo'])
#-#        table_obj.__table__.drop(bind=engine)
        table_obj.__table__.create(bind=engine)
Пример #4
0
    def __init__(self, conf_path='config/pn_conf.yaml'):
        global attachment_dir
        self.conf_path = os.path.abspath(conf_path)
        self.conf = getConf(self.conf_path, root_key='itchat')

        attachment_dir = os.path.abspath(self.conf['attachment_dir'])

        self.thread_id = None

        self.gid = None  # 记录我们群的UserName
        if self.conf['use_custom_manager']:
            # create proxy manager
            class MySyncManager(SyncManager):
                pass

            MySyncManager.register('get_wx_send_q')
            mgr = MySyncManager(
                (get_lan_ip(), self.conf['custom_manager_port']),
                self.conf['custom_manager_authkey'].encode('utf8'))
            #-#            sleep(0.5)  # wait for manager to start
            mgr.connect()

            self.q_send = mgr.get_wx_send_q()
        else:
            mgr = multiprocessing.Manager()
            self.q_send = mgr.Queue()
        self.event_exit = mgr.Event()
        multiprocessing.current_process(
        ).authkey = self.conf['custom_manager_authkey'].encode(
            'utf8')  # https://bugs.python.org/issue7503
        self.proc_wx = multiprocessing.Process(target=self.run,
                                               args=(self.event_exit,
                                                     self.q_send))
        self.proc_wx.start()
Пример #5
0
    def __init__(self, conf_file='./config/pn_conf.yaml', loop=None):
        # conf
        self.conf_file_path = os.path.abspath(conf_file)
        conf = getConf(self.conf_file_path)
        self.all_conf = conf
        self.conf = self.all_conf['prom_notify']
        # proc title
        setproctitle(self.all_conf['proc_title'])
        # start remote manager
        self.mm = MyManager(self.conf_file_path)
        # audio module 提前创建是为了使子进程占用内存小一点
        self.ps = PlaySound(self.conf_file_path)
        self.loop = loop
        self.net = NetManager(conf_path=self.conf_file_path, loop=self.loop, event_notify=event_notify)
        # history data
#-#        self.his = HistoryDB(self.conf_file_path)
        # progress data
        self.progress = ProgressData(os.path.abspath(self.conf['progress_file']))
        # filter module
        self.filter = FilterTitle(self.conf_file_path, event_notify)
        # coupon module
        self.coupon = CouponManager(self.conf_file_path, event_notify)

        self.p_price = re.compile(r'\s*(?:¥|券后)?([0-9\.]+)')
        self.p_chinese = re.compile('[\u4e00-\u9fa5]+')

        # 发送内容到微信
        self.wx = None
        if self.conf['enable_wx']:
            self.wx = ItchatManager(self.conf_file_path)
Пример #6
0
 def __init__(self, conf_path='config/pn_conf.yaml'):
     # input param
     self.conf_path = conf_path
     self.conf = getConf(self.conf_path, root_key='audio')
     if self.conf['target'] == 'pi':
         self.t2s = Text2SpeechBaidu(self.conf_path)  # sync
     else:
         self.t2s = Text2SpeechXunFei(self.conf_path)  # sync
     self.executor_t2s = concurrent.futures.ProcessPoolExecutor(2)  # async
     if self.conf['use_custom_manager']:
         # create proxy manager
         mgr = SyncManager(
             (get_lan_ip(), self.conf['custom_manager_port']),
             self.conf['custom_manager_authkey'].encode('utf8'))
         sleep(0.5)  # wait for manager to start
         mgr.connect()
     else:
         mgr = multiprocessing.Manager()
     self.q_audio = mgr.Queue()
     #-#        debug('audio data queue created. %s', self.q_audio)
     self.event_exit = mgr.Event()
     multiprocessing.current_process(
     ).authkey = self.conf['custom_manager_authkey'].encode(
         'utf8')  # https://bugs.python.org/issue7503
     self.proc_play = multiprocessing.Process(target=self.playAudioFromQ,
                                              args=(self.q_audio,
                                                    self.event_exit))
     self.proc_play.start()
     #-#        debug('play background proc start. %s', self.proc_play)
     # 触发进程池worker进程创建, 貌似提前创建的占用内存小些
     self.executor_t2s.map(noop_func, (None, None))
Пример #7
0
def run(server_class=http.server.ThreadingHTTPServer, handler_class=MyHandler):
    conf_path = os.path.abspath('config/pn_conf.yaml')
    conf = getConf(conf_path, root_key='sis_server')
    server_address = (conf['host'], conf['port'])
    handler_class.loadCfg()
    httpd = server_class(server_address, handler_class)
    info(f'listen on {server_address} ...\nhttp://{conf["host"]}:{conf["port"]}/')
    httpd.serve_forever()
    info('done.')
Пример #8
0
    def __init__(self, conf_path='config/pn_conf.yaml', event_notify=None):
        self.conf_path = os.path.abspath(conf_path)
        self.conf = getConf(self.conf_path, root_key='discuz')

        self.loop = None
        self.event_notify = event_notify
        if self.conf['geckodriver'] not in sys.path:
            sys.path.append(self.conf['geckodriver'])
        self.net = None
Пример #9
0
 def loadCfg(cls):
     # 加载配置
     cls.conf_path = os.path.abspath('config/pn_conf.yaml')
     cls.all_conf = getConf(cls.conf_path)
     cls.conf = cls.all_conf['sis_server']
     cls.discuz_conf = cls.all_conf['discuz']
     # 其他配置
     cls.pageSize = 10
     cls.pPage = re.compile('^/(\d+)')
Пример #10
0
 def __init__(self, conf_path='config/pn_conf.yaml'):
     # input param
     self.conf_path = conf_path
     self.conf = getConf(self.conf_path, root_key='remote_manager')
     # create remote manager
     p_mgr = multiprocessing.Process(
         target=server_manager,
         args=((get_lan_ip(), self.conf['custom_manager_port']),
               self.conf['custom_manager_authkey'].encode('utf8')))
     p_mgr.start()
Пример #11
0
    def __init__(self, conf_path='config/pn_conf.yaml', event_notify=None):
        self.conf_path = os.path.abspath(conf_path)
        self.conf = getConf(self.conf_path, root_key='coupon')

        self.event_notify = event_notify
        self.jd_user = self.conf['jd_user']
        self.jd_password = self.conf['jd_password']

        self.ff_jr = None
        if getuser() != 'pi':  # orangepi 上不检查优惠券信息
            pass
Пример #12
0
    def __init__(self, conf_path='config/pn_conf.yaml'):
        # input param
        self.conf_path = conf_path
        self.from_text = None  # 保存短小的待转换文字
        self.from_file = None
        self.to_file = None
        self.only_print_result = None
        self.short_mode = None
        self.conf = getConf(self.conf_path, root_key='t2s')
        if __name__ == '__main__':
            self.getArgs()

        # interval use
        self.dl = None  # msc handler
Пример #13
0
    def __init__(self, loop=None):
        self.loop = loop
        self.conf = getConf('config/dn.yaml')

        resolver = AsyncResolver(nameservers=['8.8.8.8', '8.8.4.4'])
        conn = aiohttp.TCPConnector(resolver=resolver, limit=10)
        if self.loop:
            self.sess = aiohttp.ClientSession(
                connector=conn,
                headers={'User-Agent': self.conf['user_agent']},
                loop=self.loop)
        else:
            self.sess = aiohttp.ClientSession(
                connector=conn,
                headers={'User-Agent': self.conf['user_agent']})
Пример #14
0
    def __init__(self, conf_path='config/pn_conf.yaml', event_notify=None):
        self.conf_path = os.path.abspath(conf_path)
        self.conf = getConf(self.conf_path, root_key='filter')

        self.event_notify = event_notify
        self.filter_path = os.path.abspath(self.conf['filter_path'])

        self.l_include_coupon = list()
        self.l_exclude_coupon = list()
        self._loadIncludeExcludeData()

        self.jieba_userdict_path = None
        self.jieba_userdict = None
        self.jieba_strip_word = None
        self._initJieba()
Пример #15
0
 def __init__(self, conf_path='config/pn_conf.yaml'):
     self.conf_path = os.path.abspath(conf_path)
     self.conf = getConf(self.conf_path, root_key='db')
     assert self.conf['type'] in ('sqlite', 'mysql')
     if self.conf['type'] == 'sqlite':
         #-#            self.db = SqliteDatabase(os.path.abspath(self.conf['path']), autocommit=False)
         self.db = SqliteDatabase(os.path.abspath(self.conf['path']))
     elif self.conf['type'] == 'db_url':
         # http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#database-url
         # mysql: mysql://user:passwd@ip:port/my_db
         # mysql with pool: mysql+pool://user:passwd@ip:port/my_db?max_connections=20&stale_timeout=300
         # postgresql: postgresql://postgres:my_password@localhost:5432/my_database will
         # sqlit: sqlite:///my_database.db
         # sqlite in memory: sqlite:///:memory:
         self.db = connect(self.conf['path'])
     db_proxy.initialize(self.db)
     self.db.connect()
Пример #16
0
    def _loadIncludeExcludeData(self, force_reload=False):
        """重新从配置文件读取关注/排除词, 作为自定义词组添加到结巴
        """
        conf = getConf(self.filter_path, force_reload=force_reload)
        self.l_concern = conf['l_concern']
        # 将enable=False的关注项去掉
        self.l_concern = [x for x in self.l_concern if x.get('enable', True) is True]
        debug(f'concern item(s) loaded {len(self.l_concern)}')
        self.l_include_coupon = conf['l_include_coupon'] or []
        self.l_exclude_coupon = conf['l_exclude_coupon'] or []
        debug('include/exclude coupon item(s) loaded. %s/%s ', len(self.l_include_coupon), len(self.l_exclude_coupon))

        self.l_include_jr_coupon = conf['l_include_jr_coupon'] or []
        self.l_exclude_jr_coupon = conf['l_exclude_jr_coupon'] or []
        debug('include/exclude jr coupon item(s) loaded. %s/%s ', len(self.l_include_jr_coupon), len(self.l_exclude_jr_coupon))
        if force_reload:
            self._addUserWord()
Пример #17
0
    def _loadIncludeExcludeData(self, force_reload=False):
        """重新从配置文件读取关注/排除词, 作为自定义词组添加到结巴
        """
        conf = getConf(self.filter_path, force_reload=force_reload)
        self.st_include, self.st_exclude = set(conf['l_include']
                                               or []), set(conf['l_exclude']
                                                           or [])
        debug('include/exclude item(s) loaded. %s/%s ', len(self.st_include),
              len(self.st_exclude))
        self.l_include_coupon = conf['l_include_coupon'] or []
        self.l_exclude_coupon = conf['l_exclude_coupon'] or []
        debug('include/exclude coupon item(s) loaded. %s/%s ',
              len(self.l_include_coupon), len(self.l_exclude_coupon))

        self.l_include_jr_coupon = conf['l_include_jr_coupon'] or []
        self.l_exclude_jr_coupon = conf['l_exclude_jr_coupon'] or []
        debug('include/exclude jr coupon item(s) loaded. %s/%s ',
              len(self.l_include_jr_coupon), len(self.l_exclude_jr_coupon))
        if force_reload:
            self._addUserWord()
Пример #18
0
    def __init__(self,
                 conf_path='./config/pn_conf.yaml',
                 loop=None,
                 event_notify=None):
        self.conf_path = os.path.abspath(conf_path)
        self.conf = getConf(self.conf_path, root_key='net')

        self.loop = None
        self.sess = None
        #-#        resolver = AsyncResolver(nameservers=['8.8.8.8', '8.8.4.4', '1.1.1.1'])
        #-#        conn = aiohttp.TCPConnector(resolver=resolver, limit=10, ttl_dns_cache=300)
        conn = aiohttp.TCPConnector(limit=10, ttl_dns_cache=300)
        if self.loop:
            self.sess = aiohttp.ClientSession(
                connector=conn,
                headers={'User-Agent': self.conf['user_agent']},
                loop=self.loop)
        else:
            self.sess = aiohttp.ClientSession(
                connector=conn,
                headers={'User-Agent': self.conf['user_agent']})
        info('sess inited.')
Пример #19
0
    def __init__(self, conf_path='config/pn_conf.yaml'):
        self.conf_path = os.path.abspath(conf_path)
        self.conf = getConf(self.conf_path)
        self.mgr = None
        self.send_q = None
        if self.conf['prom_notify']['enable_wx']:
            itchat_conf = self.conf['itchat']
            if itchat_conf['use_custom_manager']:
                # create proxy manager
                class MySyncManager(SyncManager):
                    pass

                MySyncManager.register('get_wx_send_q')
                self.mgr = MySyncManager(
                    (get_lan_ip(), itchat_conf['custom_manager_port']),
                    itchat_conf['custom_manager_authkey'].encode('utf8'))
                self.mgr.connect()
                self.send_q = self.mgr.get_wx_send_q()  # 获取到了发送队列
            else:
                warn(
                    'itchat not use custom manager, can\'t send msg via wx !!!'
                )
        else:
            warn('wx not enabled, can\'t send msg via wx !!!')
Пример #20
0
 def __init__(self, conf_path='config/pn_conf.yaml'):
     self.conf_path = os.path.abspath(conf_path)
     self.conf = getConf(self.conf_path, root_key='orm')
     self.sess_factory = SessionMaker.getSessMaker(self.conf['conn_str'], self.conf['echo'])