def sound_notice(sound_name): """ 以多线程的方式播放一段音频文件 :param sound_name: :return: """ try: t = threading.Thread(target=play_music, args=(sound_name, )) return t except Exception as e: ExceptionInfo(e)
def remove_file(cls, file): """ :param file:like "f:zjf/love.png" :return: """ try: os.remove(file) except Exception as e: # by:modify leungjian==print(e)->ExceptionInfo(e) # The same place behind is the same ExceptionInfo(e)
def play_music(sound, second=10): """ 播放一段声音文件 :param second: 播放的时间 :param sound:文件名 :return: """ try: # sys.path[1] # file = project_dir + '\Calf\Files\\' + sound # pygame.mixer.init() # # print("播放音乐1") # track = pygame.mixer.music.load(file) # pygame.mixer.music.play() # time.sleep(second) # pygame.mixer.music.stop() pass except Exception as e: ExceptionInfo(e) pass
def get_all_nodes_and_relationships_from_enterprise(self, etp): """ 创建从公司基本信息可以看出的关系: 1.person-[lr]->enterprise 2.person-[be_in_office]->enterprise 3.enterprise-[located]->address 4.person|enterprise-[holding]->enterprise 5.enterprise-[have]->telephone 6.enterprise-[have]->email :param : :return: """ # 如果关系上的节点不存在,数据库同样会补充创建节点,这一点很重要 nodes, rps = [], [] etp_n = self.get_neo_node(etp) if etp_n is None: self.logger.debug('{} filed initialize enterprise ' 'Neo node'.format(etp['NAME'])) return nodes, rps nodes.append(etp_n) try: lr = etp.get_legal_representative() # 法定代表人有可能会是以下这些对象 lr_n = self.match_node( *['Person'] + legal, cypher='_.URL = "{}"'.format(lr['URL']) ) if lr_n is None: lr_n = self.get_neo_node(lr) if lr_n is None: self.logger.debug('{} filed initialize legal representative ' 'Neo node'.format(etp['NAME'])) else: nodes.append(lr_n) rps.append(LegalRep(lr_n, etp_n)) except Exception as e: ExceptionInfo(e) self.logger.error('{} deal legal representative raise ' '({})'.format(etp['NAME'], e), exc_info=True) try: ms = etp.get_manager() if len(ms): for m in ms: # 主要人员 下面必然是人 m_n = m.pop('person') m_n = self.get_neo_node(m_n) if m_n is None: self.logger.debug('{} filed initialize major manager ' 'Neo node'.format(etp['NAME'])) else: nodes.append(m_n) rps.append(BeInOffice(m_n, etp_n, **m)) except Exception as e: self.logger.error('{} deal major managers raise ' '({})'.format(etp['NAME'], e), exc_info=True) try: dz = etp.get_address() dz_n = self.get_neo_node(dz) if dz_n is None: self.logger.debug('{} filed initialize address ' 'Neo node'.format(etp['NAME'])) else: nodes.append(dz_n) rps.append(Located(etp_n, dz_n)) except Exception as e: self.logger.error('{} deal address raise ' '({})'.format(etp['NAME'], e), exc_info=True) try: sh = etp.get_share_holder() if len(sh): for s in sh: s_ = s.pop('share_holder') # 股东有可能会是以下这些对象 sh_n = self.match_node( 'Person', cypher='_.URL = "{}"'.format(s_['URL']) ) if sh_n is None: sh_n = self.match_node( *legal, cypher='_.URL = "{}" OR _.NAME = "{}"'.format( s_['URL'], s_['NAME']) ) if sh_n is None: # 在以有的对象里面没找到这个股东 # 创建这个意外的股东 sh_n = self.get_neo_node(s_) if sh_n is None: self.logger.debug('{} filed initialize unexpected share ' 'holder Neo node'.format(etp['NAME'])) if sh_n is not None: nodes.append(sh_n) rps.append(Share(etp_n, sh_n, **s)) except Exception as e: self.logger.error('{} deal share holder raise ' '({})'.format(etp['NAME'], e), exc_info=True) try: tel = etp.get_telephone_number() if tel is None: # self.to_logs('there is not valid telephone for' # ' this enterprise.', 'ERROR', eb['name']) pass else: tel_n = self.get_neo_node(tel) if tel_n is None: self.logger.debug('{} filed initialize telephone ' 'Neo node'.format(etp['NAME'])) else: nodes.append(tel_n) rps.append(Have(etp_n, tel_n)) pass except Exception as e: self.logger.error('{} deal telephone number raise ' '({})'.format(etp['NAME'], e), exc_info=True) try: eml = etp.get_email() if eml is None: # self.to_logs('there is not valid email for' # ' this enterprise.', 'ERROR', eb['name']) pass else: eml_n = self.get_neo_node(eml) if eml_n is None: self.logger.debug('{} filed initialize email ' 'Neo node'.format(etp['NAME'])) else: nodes.append(eml_n) rps.append(Have(etp_n, eml_n)) pass except Exception as e: self.logger.debug('{} deal email raise ({})' ''.format(etp['NAME'], e), exc_info=True) try: ivs = etp.get_invest_outer() if len(ivs): for iv in ivs: iv_ = iv.pop('invested') # 被投资企业可能是下面这些对象 iv_n = self.match_node( *legal, cypher='_.URL = "{}" OR _.NAME = "{}"'.format( iv_['URL'], iv_['NAME']) ) if iv_n is None: iv_n = self.get_neo_node(iv_) if iv_n is None: self.logger.debug('{} filed initialize unexpected invested ' 'Neo node'.format(etp['NAME'])) continue nodes.append(iv_n) rps.append(Investing(etp_n, iv_n, **iv)) except Exception as e: self.logger.error('{} deal invest raise ({})' ''.format(etp['NAME'], e), exc_info=True) try: brs = etp.get_branch() if len(brs): for b in brs: b_ = b.pop('branch') # 分支机构可能是下面这些对象 b_n = self.match_node( *legal, cypher='_.URL = "{}" OR _.NAME = "{}"'.format( b_['URL'], b_['NAME']) ) if b_n is None: b_n = self.get_neo_node(b_) if b_n is None: self.logger.debug('{} filed initialize unexpected branch ' 'Neo node'.format(etp['NAME'])) continue p_ = b['principal'] p_n = self.get_neo_node(p_) if p_n is not None: nodes.append(p_n) rps.append(Principal(p_n, b_n)) b.pop('principal') nodes.append(b_n) rps.append(BranchAgency( etp_n, b_n, **b )) except Exception as e: self.logger.error('{} deal branch raise ({})' ''.format(etp['NAME'], e), exc_info=True) try: hcs = etp.get_head_company() if len(hcs): for h in hcs: h_ = h.pop('head') # 总公司可能是下面这些对象 h_n = self.match_node( *legal, cypher='_.URL = "{}" OR _.NAME = "{}"'.format( h_['URL'], h_['NAME']) ) if h_n is None: h_n = self.get_neo_node(h_) if h_n is None: self.logger.debug('filed initialize unexpected head ' 'company Neo node'.format(etp['NAME'])) continue p_ = h['principal'] p_n = self.get_neo_node(p_) if p_n is not None: nodes.append(p_n) rps.append(Principal(p_n, h_n)) h.pop('principal') nodes.append(h_n) rps.append(SuperiorAgency( etp_n, h_n, **h )) except Exception as e: self.logger.error('{} deal head company raise ({})' ''.format(etp['NAME'], e), exc_info=True) try: cps = etp.get_construction_project() if len(cps): for c in cps: c_ = c.pop('project') c_n = self.get_neo_node(c_) if c_n is None: self.logger.debug('filed initialize unexpected construction ' 'project Neo node'.format(etp['NAME'])) continue jsdw = c.pop('jsdw') # 查询这个建设单位是否已经存在 j_n = self.match_node( *legal, cypher='_.URL = "{}" OR _.NAME = "{}"'.format( jsdw['URL'], jsdw['NAME']) ) if j_n is None: j_n = self.get_neo_node(jsdw) if j_n is None: self.logger.debug('filed initialize unexpected construction ' 'agency Neo node'.format(etp['NAME'])) continue # TODO(lj):需要考虑是否将承建、建设单独列为一种关系 nodes.append(c_n) rps.append(Have( etp_n, c_n, **dict(角色='承建单位', **c) )) nodes.append(j_n) rps.append(Have( j_n, c_n, **dict(角色='建设单位', **c) )) except Exception as e: self.logger.error('{} deal construction project raise ({})' ''.format(etp['NAME'], e), exc_info=True) try: ccs = etp.get_construction_certificate() if len(ccs): for c in ccs: c_ = c.pop('ctf') c_n = self.get_neo_node(c_) if c_n is None: self.logger.debug('filed initialize unexpected construction ' 'certificate Neo node'.format(etp['NAME'])) continue nodes.append(c_n) rps.append(Have(etp_n, c_n, **c)) except Exception as e: ExceptionInfo(e) self.logger.error('deal construction certificate raise ({})' ''.format(etp['NAME'], e), exc_info=True) return nodes, rps
def get_all_nodes_from_enterprise(self, etp): nodes = [etp] try: lr = etp.get_legal_representative() if lr.isPerson(): nodes.append(lr) except Exception as e: self.to_logs('deal legal representative raise ({})' ''.format(e), 'EXCEPTION', etp['NAME']) try: ms = etp.get_manager() if len(ms): nodes += [m['person'] for m in ms] except Exception as e: self.to_logs('deal major managers raise ({})'.format(e), 'EXCEPTION', etp['NAME']) try: nodes.append(etp.get_address()) except Exception as e: self.to_logs('deal address raise ({})'.format(e), 'EXCEPTION', etp['NAME']) try: nodes.append(etp.get_telephone_number()) pass except Exception as e: ExceptionInfo(e) self.to_logs('deal telephone number raise ({})'.format(e), 'EXCEPTION', etp['NAME']) try: nodes.append(etp.get_email()) pass except Exception as e: ExceptionInfo(e) self.to_logs('deal email raise ({})'.format(e), 'EXCEPTION', etp['NAME']) try: cps = etp.get_construction_project() if len(cps): nodes += [ c.pop('project') for c in cps ] except Exception as e: ExceptionInfo(e) self.to_logs('deal construction project raise ({})'.format(e), 'EXCEPTION', etp['NAME']) try: ccs = etp.get_construction_certificate() nodes += [c.pop('ctf') for c in ccs] except Exception as e: ExceptionInfo(e) self.to_logs('deal construction certificate raise ({})'.format(e), 'EXCEPTION', etp['NAME']) try: sh = etp.get_share_holder() if len(sh): _nds_ = [] for s in sh: _s_ = s.pop('share_holder') if _s_.isPerson(): _nds_.append(_s_) nodes += _nds_ except Exception as e: ExceptionInfo(e) self.to_logs('deal share holder raise ({})'.format(e), 'EXCEPTION', etp['NAME']) try: brs = etp.get_branch() if len(brs): _nds_ = [] for b in brs: _p_ = b['principal'] if _p_.isPerson(): _nds_.append(_p_) nodes += _nds_ except Exception as e: ExceptionInfo(e) self.to_logs('deal branch raise ({})'.format(e), 'EXCEPTION', etp['NAME']) try: hcs = etp.get_head_company() if len(hcs): _nds_ = [] for h in hcs: _p_ = h['principal'] if _p_.isPerson(): _nds_.append(_p_) nodes += _nds_ except Exception as e: ExceptionInfo(e) self.to_logs('deal head company raise ({})'.format(e), 'EXCEPTION', etp['NAME']) return nodes
def move_file(cls, src, dst): try: shutil.move(src=src, dst=dst) except Exception as e: ExceptionInfo(e)
def copy_file(cls, src, dst): try: shutil.copy(src=src, dst=dst) except Exception as e: ExceptionInfo(e)