def get_info(self): # self.driver.implicitly_wait(15) # 显性等待 try: self.driver.get(self.cp_url) self.driver.find_element_by_xpath( '//input[@id="gover_search_key"]').click() self.driver.find_element_by_xpath( '//input[@id="gover_search_key"]').send_keys(self.company) self.driver.find_element_by_xpath( "//button[@class='head_search_btn']").click() except Exception as e: print("*" * 10, str(e)) Log('log/cp_log.log', e=e) return ["获取网页内容时出现异常"] time.sleep(10) html_list = [] page = 1 while 1: # [['(2016)京01民终7217号', '2016-12-19', '北京市第一中级人民法院', '魏巍等劳动争议二审民事判决书', ['民事', '二审'], 'http://wenshu.court.gov.cn/content/content?DocID=d4117425-9198-40a2-8a98-3711404e253b&KeyWord=深圳市中合银融资担保有限公司'], ['(2017)粤03民终2926号', '2017-05-12', '广东省深圳市中级人民法院', '江西中联建设集团有限公司与', ['民事', '二审'], 'http://wenshu.court.gov.cn/content/content?DocID=5d5cf5a2-2531-416b-9516-a85101011a03&KeyWord=深圳市中合银融资担保有限公司'], ['(2016)粤03民辖终3827、3828号', '2016-11-17', '广东省深圳市中级人民法院', '旭东电力集团有限公司与', ['民事', '二审'], 'http://wenshu.court.gov.cn/content/content?DocID=fe883891-d1a8-44a3-a23c-1f67a0349cb7&KeyWord=深圳市中合银融资担保有限公司'], ['(2016)粤0304民初18775-18776号', '2016-09-21', '深圳市福田区人民法院', '与旭东电力集团有限公司罗云富保证合同纠纷一审民事裁定书', ['民事', '一审'], 'http://wenshu.court.gov.cn/content/content?DocID=1c55cb08-667d-48eb-9dae-a7f4010e73cc&KeyWord=深圳市中合银融资担保有限公司'], ['(2016)粤0304民初18775-18776号之一', '2017-07-10', '深圳市福田区人民法院', '与旭东电力集团有限公司、罗云富保证合同纠纷一审民事裁定书', ['民事', '一审'], 'http://wenshu.court.gov.cn/content/content?DocID=197c2dfb-7520-4b7d-9598-a7f4010e73f2&KeyWord=深圳市中合银融资担保有限公司']] try: html = self.driver.page_source h = Handel_html(html=html) result = h.pd_html() if not result: self.driver.quit() return ["无符合条件的数据"] except Exception as e: Log('log/cp_log.log', e=e) html = "获取网页内容时出现异常" html_list.append(html) break html_list.append(html) try: self.driver.implicitly_wait(15) self.driver.find_element_by_xpath('//a[@class="next"]').click() except: # 将错误写入日志 # print('发生异常') self.driver.quit() break time.sleep(10) page += 1 return html_list
def __init__(self, company): u = Rand_ua() ua = u.rand_chose() try: options = webdriver.ChromeOptions() options.add_argument('--user-agent={}'.format(ua)) self.driver = webdriver.Chrome(chrome_options=options) except Exception as e: Log('log/cp_log.log', e=e) return self.cp_url = "http://wenshu.court.gov.cn/" self.company = company
def get_detail(self, href): # /content/content?DocID=b18f2733-6f07-4d42-ab8b-d1859ce3222f&KeyWord=江苏和信工程咨询有限公司' # http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx?DocID=d47506cc-644b-4c51-bffe-a71c0102f2b9 if href != "未获取到文书id": d_id = re.findall(r"DocID=(.*?)&", href) doc_id = d_id[0] if d_id else 0 if doc_id: u = Rand_ua() ua = u.rand_chose() headers = {"User-Agent": ua} d_url = "http://wenshu.court.gov.cn/CreateContentJS/CreateContentJS.aspx?DocID={}".format( doc_id) print(d_url) try: ret = requests.get(d_url, headers=headers, timeout=60) except Exception as e: print("*" * 10, str(e)) Log('log/cp_log.log', e=e) return "获取文书内容失败" try: html = ret.content.decode() # print(html) xml = etree.HTML(html) except Exception as e: print("*" * 10, str(e)) Log('log/cp_log.log', e=e) return "获取文书内容失败" try: ws_detail = xml.xpath("//body//text()") except Exception as e: print("*" * 10, str(e)) Log('log/cp_log.log', e=e) return "获取文书内容失败" time.sleep(2) return ws_detail else: return "未获取到文书id"
def __init__(self, company): u = Rand_ua() ua = u.rand_chose() try: options = webdriver.ChromeOptions() path = "E:\python开发环境\chromedriver.exe" options.add_argument('--user-agent={}'.format(ua)) # options.add_argument("headless") # prefs = {'profile.default_content_setting_values': {'images': 2}} # options.add_experimental_option('prefs', prefs) # 采用无图模式效果不理想 self.driver = webdriver.Chrome(chrome_options=options,executable_path=path) except Exception as e: Log('log/cp_log.log', e=e) # self.display.stop() return self.cp_url = "http://wenshu.court.gov.cn/" self.company = company
def convertRTKLIBLogToRINEX(self, log_path, rinex_version="3.01"): print("Converting log " + log_path + "...") result = None # check if extension format is in the list of the supported ones log_format = [ f for f in self.supported_log_formats if log_path.endswith(f) ] if log_format: try: log_metadata = self.convertLogToRINEX(log_path, log_format[0], rinex_version) except ValueError: return None if log_metadata: result = Log(log_path, log_metadata) return result
def convertRTKLIBLogToRINEX(self, log_path, rinex_version="3.01"): print("Converting log " + log_path + "...") result = None # check if extension format is in the list of the supported ones log_format = [ f for f in self.supported_log_formats if log_path.endswith(f) ] if log_format: log_metadata = self.convertLogToRINEX(log_path, log_format[0], rinex_version) if log_metadata: result = Log(log_path, log_metadata) else: print("Error: Log invalid, or file extension is wrong") else: print("Error: Bad file extension") return result
def main(): try: if (len(sys.argv) >= 2): log = Log("logUser.txt") namedir = sys.argv[1] client_ON = True try: network = Pyro5.api.Proxy("PYRONAME:Server") myId = network.connect(load_name_files(namedir)) except (Pyro5.errors.CommunicationError): print("Server:OFF") myId = -1 if (myId >= 0): try: t_network = threading.Thread( target=insert_client_in_network, args=(myId, )) t_network.daemon = True t_network.start() except KeyboardInterrupt: print(network.disconnect(myId)) print("Hello. Welcome a network!! Your id is ", myId) else: print("Sorry =( ") client_ON = False else: print( "Missing argument with your directory name: Ex.:python3 clientM myDirFiles" ) client_ON = False while (client_ON): op = int( input( "Your options:\n[1] Show all files\n[2] Download\n[3] Update\n[4] Show file\n[5] Exit\n" )) os.system('clear') if (op == 1): print(network.show_filenames(myId)) elif (op == 2): filename = str(input("What is the desired file name?\n")) ids = network.files_id(filename) idNeig = load_balancing(myId, ids) if (myId == idNeig): print("Fail download") print("You already have the file") else: torrent = Pyro5.api.Proxy("PYRONAME:Client:" + str(idNeig)) content = torrent.download(filename) if (content == -1): print("Fail download") else: print("Sucess download") filename_new = os.getcwd( ) + '/' + sys.argv[1] + '/' + filename new_file = open(filename_new, 'w') new_file.write(content) new_file.close() network.update_files(myId, load_name_files(namedir)) log.new_log( "FILE TRANSFER CLIENT:{} -> CLIENT:{} NAME FILE:{}" .format(idNeig, myId, filename)) elif (op == 3): network.update_files(myId, load_name_files(namedir)) elif (op == 4): idNeig = int(input("What's the neighbor's ID?\n")) filename = str(input("What is the desired file name?\n")) if (idNeig == myId): filename_new = os.getcwd( ) + '/' + sys.argv[1] + '/' + filename content = getFile(filename_new) print("Name file {}\nCONTENT:".format(filename)) print(content) log.new_log("SHOW FILE CLIENT:{} FILE:{}".format( myId, filename)) else: torrent = Pyro5.api.Proxy("PYRONAME:Client:" + str(idNeig)) content = torrent.download(filename) if (content == -1): print("None") else: print("Name file {}\nCONTENT:".format(filename)) print(content) log.new_log("SHOW FILE DO CLIENT:{} FILE:{}".format( idNeig, filename)) elif (op == 5): client_ON = False print(network.disconnect(myId)) else: print("Option doesn't exists =(") #t_network.join() except (KeyboardInterrupt): print("\nBye!") print(network.disconnect(myId))
def run(self, verbose=False, iterations=3000): logs = Log() logs.log("Iterations: " + str(iterations)) logs.log("Action Method: random") pygame.time.delay(100) self.print_screen() while self.running and not self.curState.IsTerminal(): self.print_screen() pygame.display.update() # Agent's Turn if self.curState.Turn == 2: initTime = time() agent = Agent(self.curState, actionMethod="random") node = agent.findNextAction(3000) action = node.state.LastAction self.curState.ApplyAction(action) endTime = time() logs.RegisterLastAction( State.NextPlayerTurn(self.curState.Turn), action, node.wins, node.visits, endTime - initTime) if verbose: print(logs.LastActionStatistics()) # Player's Turn for event in pygame.event.get(): if event.type == QUIT: self.running = False if event.type == MOUSEBUTTONDOWN: x = event.pos[0] if self.curState.Turn == 1: for i in range(7): if self.circle[0][i][ 0] - 20 <= x and x <= self.circle[0][i][ 0] + 20: if self.curState.ValidMove(i): self.curState.ApplyAction(i) logs.RegisterLastAction( State.NextPlayerTurn( self.curState.Turn), i, 0, 0, 0) self.print_screen() pygame.display.update() winner = self.curState.WhoWin() if verbose: print("winner: ", winner) font = pygame.font.Font(None, 48) text = font.render("Winner: " + str(winner), False, (0, 0, 0)) self.screen.blit(text, (20, 20)) pygame.display.update() logs.SaveData() ed = False while True: if ed: break for event in pygame.event.get(): if event.type == QUIT: ed = True pygame.quit()
import argparse import logging import sys from cmds import parse_cmd_hash from cmds import parse_cmd_help from cmds import parse_cmd_tcp from cmds import parse_cmd_udp from const import APPLICATION_NAME from const import LOGS_DIR from const import LOGS_TARGET from logs import Log # initialize logger instance log = Log(target=LOGS_TARGET, level=logging.DEBUG, path=LOGS_DIR, app=APPLICATION_NAME) # application start if __name__ == '__main__': # command parser cmd_parser = argparse.ArgumentParser(prog=APPLICATION_NAME) sub_parser = cmd_parser.add_subparsers() cmd_map = dict() cmd_map['tcp'] = { 'sub_parser': sub_parser.add_parser('tcp'), 'func': parse_cmd_tcp } cmd_map['udp'] = { 'sub_parser': sub_parser.add_parser('udp'), 'func': parse_cmd_udp
import Pyro5.api from logs import Log max_size = 50 clients = [] files = [] log = Log('logAdm.txt') #Gerencia a geração de id's e verifica o limite de clientes na rede def verrified_limit(file): idC = 0 if (len(clients) < max_size): for i in clients: if (i == -1): clients[idC] = idC files[idC] = file return idC idC += 1 clients.append(idC) files.append(file) return idC else: for i in clients: if (i == -1): clients[idC] = idC files[idC] = file