def main(): if len(argv) <= 1: print(usage) else: for path in argv[1:]: with open(path, "r") as file: parser(file, path)
def traverse(court, proptype, saletype, key): addr = "http://aomp.judicial.gov.tw/abbs/wkw/WHD2A03.jsp?" + \ key + \ "&hsimun=all&ctmd=all&sec=all&saledate1=&saledate2=&crmyy=&crmid=&crmno=&" + \ "dpt=&minprice1=&minprice2=&saleno=&area1=&area2=®isteno=&checkyn=all&" + \ "emptyyn=all&rrange=不分&comm_yn=&owner1=&order=odcrm&" + \ "courtX=" + court + "&proptypeX=" + proptype + "&saletypeX=" + saletype + \ "&pageTotal=13&pageSize=15&rowStart=11&query_typeX=db&" r = requests.get(addr) soup = BeautifulSoup(r.text, "html.parser") pageTotal = soup.input['value'] print('pageTotal:' + pageTotal) page = 1 while page <= int(pageTotal): link = addr + "pageNow=" + str(page) print(link) r = requests.get(link) soup = BeautifulSoup(r.text, "html.parser") tables = soup.table.table tr = tables.find_all('tr') for i, item in enumerate(tr): if i == 0: continue td = item.find_all('td') head = 'http://aomp.judicial.gov.tw/abbs/wkw/' href = head + td[4].a['href'] print(str((page - 1) * 15 + i) + ", " + href) parser(href) # break page += 1
def main_loop(): if player.new_room: clear_screen() player.room.print_room() if player.has_won is True: sys.exit() user_input = input("$ ").lower() parser(user_input, player)
def computor(): polynome = list() expression = sys.argv[1:] if len(expression) != 1: exit_message("Wrong number of parameters") parser(polynome, expression) polynome = refacto(polynome) print_refacto(polynome) check_invalid_exponent(polynome) resolve_polynome(polynome)
def select_module(para_set): # get parameters. input_path = '' input_file = '' output_path = './' testing = False compress = '' merge = False for o, a in para_set: if o == '-p': input_path = a elif o == '-f': input_file = a elif o == '-o': output_path = a elif o == '--testing': testing = True elif o == '--compress': compress = a elif o == '--merge': merge = True else: #logging.error("unhandled option.") return False # check parameters state # only allow user use -p or -f at same time. if (bool(len(input_path)) != bool(len(input_file))) is False: return False if testing: # go to test module. return True if len(input_path) > 0: # parse all html files in folder. for file in os.listdir(input_path): if os.path.isfile(input_path + '/' + file): state = parser.parser(input_path + '/' + file, output_path, merge, compress) if state is False: continue else: print '[ok]' + file else: # parse html file. state = parser.parser(input_file, output_path, merge, compress) if state is False: return False print '[ok]' + input_file return True
def main(): if len(sys.argv) <= 1: print(usage) else: path_in = sys.argv[1] if len(sys.argv) == 3: path_out = sys.argv[2] parser(path_in, path_out) elif len(sys.argv) == 2: ext = path_in.rfind('.') path_out = path_in[:ext] + ".vtt" parser(path_in, path_out) else: print("Invalid request. See usage!\n" + usage)
def importer_rad(request): # Handle file upload if request.method == 'POST': form = FilForm(request.POST, request.FILES) if form.is_valid(): ny_fil = RADfileArchive(file=request.FILES['file']) try: ny_fil.save() except KeyError as e: return render(request, "error.html", {"error": "That's not halal json. Absolutely not haram."}) # IT DIDN'T WORK... do something! if len(RADfileArchive.objects.all()) > 0: latestRAD = str(RADfileArchive.objects.order_by('-id')[0].file.path) else: messages.error(request, "Something is horribly wrong.") latestRAD = str(RADfileArchive.objects.order_by('-id')[0].file.path) return render(reverse('scheduler:index')) Øvelse.objects.all().delete() Act.objects.all().delete() ActorInAct.objects.all().delete() FriActor.objects.all().delete() FriAct.objects.all().delete() all_actors = parser(latestRAD, -1, "actors") all_act_titles = parser(latestRAD, -1, "title") i = 0 j = 0 for act in all_act_titles: newAct = Act(actid=i, titel=act) newAct.save() i = i + 1 for actor in all_actors: newActor = ActorInAct(act=Act.objects.order_by('-id')[0], navn=actor, id=j) newActor.save() j = j + 1 # Redirect to the index after POST return redirect(reverse('scheduler:index')) else: form = FilForm() # An empty, unbound form # Render list page with the form return render( request, 'scheduler/importer_rad.html', {'form': form} )
def main(name="arithmeticExpr"): writeExpr.buildExpr(input("What depth do you want us to work on? (integer expected)\n"), name) with open(name,"r") as ae: expr = ae.read() print("The expression is:\n{}".format(expr)) n = interpreter.interpretTree(parser.parser("".join(expr.split(" ")))) print("The result is {}.".format(n))
def better_better_solution(filename): endpoints, videos, nb_caches, cache_size, all_requests = parser(filename) solution = [] caches = {i: cache_size for i in range(nb_caches)} endpoints_ordered = list(endpoints.values()) for _ in range(nb_caches): solution.append(set()) shall_we_go_on = True while shall_we_go_on: shall_we_go_on = False endpoints_ordered.sort( key=lambda x: -x["requests"][0][1] if x["requests"] else -1) for i, endpoint in enumerate(endpoints_ordered): if not endpoint["requests"]: continue if len(endpoint["requests"]) == 1: id_video, _ = endpoint["requests"][0] else: id_video, _ = endpoint["requests"][randint(0, 1)] for id_cache, _ in endpoint["caches"]: if caches[id_cache] > videos[id_video]: solution[id_cache].add(id_video) caches[id_cache] -= videos[id_video] endpoints_ordered[i]["requests"] = endpoints_ordered[i][ "requests"][1:] shall_we_go_on = True break for i in range(len(solution)): solution[i] = list(solution[i]) return solution, endpoints
def __init__(self, master): """ Start the GUI and the asynchronous threads. We are in the main (original) thread of the application, which will later be used by the GUI. We spawn a new thread for the worker. """ self.master = master # Create the queues that will be used to communicate with the GUI self.queue = Queue.Queue() self.credQueue = Queue.Queue() # Set up the GUI part self.gui = GuiPart(master, self.queue, self.endApplication, self.doScan, self.doPwn, self.credQueue) # Set up the thread to do asynchronous I/O # More can be made if necessary self.running = 1 # Start the periodic call in the GUI to check if the queue contains # anything self.periodicCall() self.router = '' self.pwning = False self.mysslstrip = sslstripRunner.sslStrip() self.myParser = parser.parser(self.credQueue) self.threadList = []
def __init__(self, title='Temp_log', min_size=(1020,560), fg='white', canvas_colour='white'): super().__init__() self._initialise_window(title, min_size, fg) self._create_canvas(canvas_colour) self._create_widgets() self._parser = parser()
def read_dependency_file(self, fname): dep_file_parser = parser.parser() self.deps_dict, self.tagged_deps, self.repos = dep_file_parser.parse( fname) for k, v in self.deps_dict.items(): self.dependencies.append(v)
def __init__(self, name, config=None, options=None, args=None, logname=None, **kwargs): self.name = name self.__dict__.update(kwargs) if not options: options, args = _parser.parser('cskpUPufmvVFw').parse_args() args = [_decode(arg) for arg in args] self.options, self.args = options, args self.name = name self.logname = logname self.ql = None config2 = _config.CONFIG.copy() if config: config2.update(config) if getattr(options, 'config_file', None): options.config_file = os.path.abspath(options.config_file) # XXX useful during testing. could be generalized with optparse callback? if not getattr(options, 'service', True): options.foreground = True self.config = _config.Config(config2, service=name, options=options) self.config.data['server_socket'] = os.getenv("KOPANO_SOCKET") or self.config.data['server_socket'] if getattr(options, 'worker_processes', None): self.config.data['worker_processes'] = options.worker_processes self.log = _log.logger(self.logname or self.name, options=self.options, config=self.config) # check that this works here or daemon may die silently XXX check run_as_user..? for msg in self.config.warnings: self.log.warn(msg) if self.config.errors: for msg in self.config.errors: self.log.error(msg) sys.exit(1) self.stats = collections.defaultdict(int, {'errors': 0}) self._server = None
def unitconverter(): #program gives directions print '''This is a unit converter written by Will Drevno. Conversions accepted are distance, weight and volume. Distances: ft cm mm mi m yd km in Weights: lb mg kg oz g Volumes: floz qt cup mL L gal pint ''' #condition being set to when program should quit q = 0 while q == 0: inputstring = raw_input('Convert [AMT SOURCE_UNIT in DEST_UNIT, or (q)uit]: ') if not inputstring == 'q': stringdata = parser(inputstring) #parses the string amount = float(stringdata[0]) #assigns each part of the separated string to a variable sourceunit = stringdata[1] destinationunit = stringdata[3] #following series of if and elif statements directs the string data to its respective function if not ' m cm mm km in ft yd mi'.find(sourceunit) == -1: output = distanceconverter(amount, sourceunit, destinationunit) elif not 'L mL floz cup pint qt gal'.find(sourceunit) == -1: output = volumeconverter(amount, sourceunit, destinationunit) elif not 'g kg mg oz lb'.find(sourceunit) == -1: output = weightconverter(amount, sourceunit, destinationunit) #formats and prints answer outputformatted = str(amount) + ' ' + sourceunit + ' = ' + str(output) + ' ' + destinationunit print outputformatted break else: #code for what to when the user hits q print 'Bye!' q = q+1
def main(file): clean = input(""" Clean up old report files?\n This will NOT delete but move old files (i.e. previously sourced data) to a directory at your current location (If you don\'t do this and choose option 1 at hte next prompt your new report data will mix mixed with the old)\n Usage: if you have previously ran this application and are running it again with the intention of specifying a new date-range. i.e. you are going to choose option 1 at the next prompt. Type y or n and press <Enter> [y/n] """) if clean == 'y': clean_up() print("----------------NEXT CHOICE-----------------") choice = choose() if choice == 1: prefix = input("What kind or report are you running: 'metered' customers or 'control' customers : ") endpoints = parser(file) generate_script(endpoints) run_report() generate_report(prefix) elif choice == 2: prefix = input("What kind or report are you running: 'metered' customers or 'control' customers : ") generate_report(prefix)
def Build_next_use_table(self): table = {} # dict of dicts of dicts lineVars = {} for start, end in self.Blocks.items(): line = {} line_2 = {} for i in range(end, start - 1, -1): if start == end: line[i] = {} else: if i is not end: instr = self.instrlist[i] instr = instr.split(', ') line[i] = dict(line[i + 1]) for v in varz["killed"]: line[i][v] = 10000 for v in varz["used"]: line[i][v] = int(instr[0]) else: line[i] = {} instr = self.instrlist[i - 1] instr = instr.split(', ') varz = parser(instr, self.variable_list) line_2[i] = [] for v in varz["killed"]: line_2[i].append(v) for v in varz["used"]: line_2[i].append(v) table[start] = line lineVars[start] = line_2 return table, lineVars
def lancer(): fini = False parser = p.parser(1) fantome = ia(parser) old_question = "" while not fini: qf = open('./1/questions.txt', 'r') question = qf.read() #print(question) q = parser.parseQuestion(question) qf.close() if question != old_question: fantome.ia_main(q) old_question = question infof = open('./1/infos.txt', 'r') lines = infof.readlines() parser.parseInfo(lines) infof.close() if len(lines) > 0: fini = "Score final" in lines[-1] qf = open('./1/questions.txt', 'r+') qf.truncate() qf.close() infof = open('./1/infos.txt', 'r+') infof.truncate infof.close() if len(lines) > 0: fini = "Score final" in lines[-1]
def main(): user_input = input("Please, type your Lisp-like function:") tokens = tokenizer(user_input) abs_syntax_tree = parser(tokens) new_ast = transformer(abs_syntax_tree) output = codeGenerator(new_ast) return output
def build(self,skip_cdiscount=False): prices={} l=[] spam_reader = parser(self.path) spam_reader.next() self.reset_count(self.train_len) print "computing prices dictionary and prices list" for row in spam_reader: if float(row[self.price_position])<=0: continue price = self.transform(float(row[self.price_position])) if smart_in(prices,price): if smart_in(prices[price],row[self.c3_position]): prices[price][row[self.c3_position]] += 1 else: prices[price][row[self.c3_position]] = 1 prices[price]['total']+=1 else: l.append(price) prices[price] = {row[self.c3_position] : 1,'total' : 1} self.smart_count() if self.loop_break: break l.sort() self.prices = prices self.p_list = l self.build_max_prices()
def main(): args = parser() solver = Solver(args) if not args.test: solver.train() else: solver.test()
def main(): start = [] global N, C N, R, pos, C = parser(sys.argv[1]) for i in range(len(pos)): start.append(tuple(pos[i])) dijkstra(start, C)
def build(path_to_file): """ Builds a list of lines grouped by date and person :return: """ message_dict = parser.parser(path_to_file) date_list = sorted(message_dict.keys()) message_list = list() last_sender = "" alignment = True # for readability later formatting has to happen, one person will be aligned left, one to the right. # if field of the tupels in list is true it means message is to be aligned left, False -> to the right for date in date_list: year, month, day = readable_date(date) message_list.append(("date", "[" + day + "." + month + "." + year + "]")) daily_messages = message_dict[date] for message in daily_messages: new_sender = message[0] if not last_sender == new_sender: alignment = not alignment last_sender = new_sender message_list.append((alignment, message[1])) return message_list
def pre_process_text(m_input): if len(m_input) is 0: return None m_map = {} m_input = auto_correct_input(m_input) language = detect_language(m_input) m_map["language"] = language k = 0 for i in filter_stopwords(m_input): current_dict = {} k += 1 input_type = get_input_type(i) current_dict["type"] = input_type m_keys = parser(i) current_dict["keys"] = m_keys list_of_synonyms = [] for key in m_keys: list_of_synonyms.append((key[0], get_synonyms(key[0]))) current_dict["synonyms"] = list_of_synonyms m_map[str(k)] = current_dict return m_map
def build(self): brands = {} spam_reader = parser(self.path) print "computing brands dictionary" self.reset_count(self.train_len) spam_reader.next() for row in spam_reader: self.smart_count() brand = self.normalized_brand(row[self.brand_position]) if self.skip_cdiscount_function(row): continue if smart_in(brands, brand): if smart_in(brands[brand], row[self.c3_position]): brands[brand][row[self.c3_position]] += 1 else: brands[brand][row[self.c3_position]] = 1 brands[brand]["total"] += 1 else: brands[brand] = {row[self.c3_position]: 1, "total": 1} if self.loop_break: break self.brands = brands self.build_max_brands()
def lancer(): fini = False parser = p.parser(0) ia = iaInspecteur(parser) old_question = "" while not fini: qf = open('./0/questions.txt', 'r') question = qf.read() #print(question) q = ia.parser.parseQuestion(question) qf.close() if question != old_question: ia.prepareAnswer(q) old_question = question infof = open('./0/infos.txt', 'r') lines = infof.readlines() ia.parser.parseInfo(lines) infof.close() if len(lines) > 0: fini = "Score final" in lines[-1] qf = open('./0/questions.txt', 'r+') qf.truncate() qf.close() print("partie finie")
def main(src): try: # On test si le fichier existe bien fo = open(src, "r") fo.close() except IOError: print("Le fichier donné n'existe pas.") return 0 with open(src) as file: exp = file.read() # On transforme la chaine d'entrée en une liste d'unité lexicale ul = scanner(exp) # On convertit cette liste en une liste contenant l'expression postfixé postfix = parser(ul) if postfix[0]: print("Chaine valide\n") # A commenter pour la lisibilité lors des test # On écrit dans un fichier, sous forme d'une pile, l'expression codegen(postfix[1]) os.chmod("a.out", 0o744) return True else: print("Erreur syntaxique à la position {}: {}.\nIl manque une partie "\ "de l'expression\n".format(postfix[1], exp[postfix[1]-1])) return False
def monitor_dport(files, target_prot, target_sport, target_ip, time_interval, data_dports): # Monitor traffic of interest: number of dst ports per time interval of target ip tmp_dport = set() start = None for filename in files: with open(filename, 'rb') as ff: header = ff.readline() for line in ff: try: ll = parser(line) except ParseError: print "ParseError: not valid line: {0}".format(line) break sa, da, sport, dport, prot = ll['sa'], ll['da'], ll[ 'sport'], ll['dport'], ll['prot'] epoch = ll['epoch'] if not start: start = epoch if start <= epoch < start + time_interval: if da == target_ip and sport == target_sport and prot == target_prot: tmp_dport.add(dport) else: while epoch >= start + time_interval: data_dports.append(len(tmp_dport)) start += time_interval tmp_dport = set() if da == target_ip and sport == target_sport and prot == target_prot: tmp_dport.add(dport) data_dports.append(len(tmp_dport))
def do_activate(self): # parser instance if self.parser is None: self.parser = parser() # We only allow a single window and raise any existing ones if self.window is None: # Windows are associated with the application # when the last one is closed the application shuts down self.window = InspektorWindow(application=self) self.add_window(self.window) if self.file is None: self.file = self.filechooser() #GLocalFile object else: self.file = self.file[0] #GLocalFile object if self.file: self.file_path = self.file.get_path() metadata = self.parser.get_jsondata(self.file_path) self.window.load_metadata(self.file, metadata) self.window.show_all() else: self.quit()
def make_html(instream, outstream, title): p = parser.parser() printer = html_printer.printer(outstream) html_printer.prelude(outstream, title) j = p.parse(instream, sys.argv[1]) amapper = abbreviation.mapper() for i in j: for k in i.results: amapper.analyse_result(k) remapper = abbreviation.remapper(amapper.shorts) peo = person.analyser() for i in j: for k in i.results: remapper.fix_result(k) peo.analyse_result(k) for i in j: printer.print_comp(i) print >>outstream, "\n" print >>outstream, "<h1>Per-person summary</h1>\n<p>Note: you can click the table headings for different sortings</p>" pp = html_printer.personlist_printer(peo.people.values(), True, outstream) pp.print_people()
def build(self, skip_cdiscount=False): prices = {} l = [] spam_reader = parser(self.path) spam_reader.next() self.reset_count(self.train_len) print "computing prices dictionary and prices list" for row in spam_reader: if float(row[self.price_position]) <= 0: continue price = self.transform(float(row[self.price_position])) if smart_in(prices, price): if smart_in(prices[price], row[self.c3_position]): prices[price][row[self.c3_position]] += 1 else: prices[price][row[self.c3_position]] = 1 prices[price]['total'] += 1 else: l.append(price) prices[price] = {row[self.c3_position]: 1, 'total': 1} self.smart_count() if self.loop_break: break l.sort() self.prices = prices self.p_list = l self.build_max_prices()
def build(self): brands = {} spam_reader = parser(self.path) print "computing brands dictionary" self.reset_count(self.train_len) spam_reader.next() for row in spam_reader: self.smart_count() brand = self.normalized_brand(row[self.brand_position]) if self.skip_cdiscount_function(row): continue if smart_in(brands, brand): if smart_in(brands[brand], row[self.c3_position]): brands[brand][row[self.c3_position]] += 1 else: brands[brand][row[self.c3_position]] = 1 brands[brand]['total'] += 1 else: brands[brand] = {row[self.c3_position]: 1, 'total': 1} if self.loop_break: break self.brands = brands self.build_max_brands()
def test_includes_excludes_both_not_empty(): import modules reload(modules) parser = parser.parser() modules.startup(parser) assert modules.modules == {} modules.shutdown(parser)
def test_include(): import modules reload(modules) parser = parser.parser() modules.startup(parser) assert modules.modules.keys()[0] == 'admin_disconnect' modules.shutdown(parser)
def test_dest(self): parse = parser("Demo.asm") dest_command_alone = parse.dest("M=M+1") dest_command_with_jump = parse.dest("M=M+1;JTE") no_dest_command = parse.dest("M+1;JTE") self.assertEqual(dest_command_with_jump, "M") self.assertEqual(dest_command_with_jump, "M") self.assertEqual(no_dest_command, "null")
def test_parser(self): param = [('BOOL', 'FAUX'), ('OP', 'ET'), ('OP', 'NON'), ('BOOL', 'VRAI')] # liste des parametres a tester result = [('BOOL', 'FAUX'), ('BOOL', 'VRAI'), ('OP', 'NON'), ('OP', 'ET')] # liste des resultats pour chaque parametre self.assertEqual(parser.parser(param), result)
def test_startup_shutdown(): import modules parser = parser.parser() assert modules.modules == {} modules.startup(parser) assert modules.modules != {} modules.shutdown(parser) assert modules.modules == {}
def calculate(self): data=self.list_datafiles[self.datafile].data parameters=self.list_datafiles[self.datafile].parameters for variable in self.info: lista=self.info[variable] if (not lista[2]) and lista[0]: string=lista[0].replace(" ","") self.info[variable][1]=np.array(eval(parser(string,parameters)))
def run(self): log.log("start running ...", log.VERBOSE) while True: readList, _, _ = select.select(self.descriptors, [], [], 2) if readList: for sock in readList: if sock == self.socket: # new connection is joining self.add_new_connection() else: msg = sock.recv(1024) host, port = sock.getpeername() if (msg): msgs = parser.parser(msg) for msg in msgs: msgType, msgBody = msg if msgType == 'username': self.ipToName[(host, port)] = msgBody log.log( "ip {} as username {}".format( host, msgBody), log.VERBOSE) room = self.ipToRoom[(host, port)] bs = "user {} enter room {}".format( msgBody, room) self.broadcase_message(room, bs) elif msgType == 'room': self.ipToRoom[(host, port)] = msgBody r = self.roomToSocks.get(msgBody) #print("room is " + msgBody) if (r == None): self.roomToSocks[msgBody] = [sock] else: self.roomToSocks[msgBody].append(sock) log.log("enter room{}".format(msgBody), log.VERBOSE) elif msgType == 'msg': # broadcast room = self.ipToRoom[(host, port)] name = self.ipToName[(host, port)] self.broadcase_message( room, "{}: {}".format(name, msgBody), sock) else: log.log( "unknown syntax recieved:{}".format( msg), log.WARNING) else: # disconnect name = self.ipToName[(host, port)] bs = "{} {}:{} disconnect".format( name, str(host), str(port)) room = self.ipToRoom[(host, port)] self.broadcase_message(room, bs) sock.close() self.descriptors.remove(sock) del self.ipToRoom[(host, port)] del self.ipToName[(host, port)] self.roomToSocks[room].remove(sock)
def __init__(self, file_name, camp_dist): #maybe folder name instead of file_name self.camp_dist_array = camp_dist self.parser = parser('../data/xlsx/start.xlsx', '../data/csv/out.csv') self.pars() self.data = sp.genfromtxt(file_name, delimiter=',', dtype='|S10') self.metrics = metrics() self.batcher = batcher(self.data) self.tth = self.batcher.tth_create()
def get_address_components(address, result_list, LANGUAGE, REGION, API_KEY,): url = 'https://maps.googleapis.com/maps/api/geocode/json?components=&language=' + LANGUAGE + '®ion=' + REGION + '&bounds=&key=' + API_KEY url = url + '&address='+ address.replace(" ","+") response = get(url) parsed_data = parser(response.json()) parsed_data['address'] = address result_list.append(parsed_data) # print(parsed_data) write_data(result_list)
def define_price_max(self): spam_reader = parser(self.path) count=0 for row in spam_reader: if float(row[self.price_position])>self.prix_max: self.prix_max=float(row[self.price_position]) count+=1 if count == self.train_len: break
def main(): im = parser(sys.argv[1]) goal = (1035, 910) # because the x,y pixel is x-column and y-row start = (144, 144) global M, N M, N = im.shape #C = np.array(imarray, copy=True) C = np.asarray(heuristic(sys.argv[2])) Astar(start, goal, C, im)
def main(): args = parser() use_cuda = torch.cuda.is_available() ## load in everything ## fpath = "./outputs/" model = Net() saved_pars = torch.load(fpath + "saved_model.pt") if use_cuda: model = model.cuda() evecs = torch.load(fpath + "top_evecs.pt") evals = torch.load(fpath + "top_evals.pt") ## get training data ## transform = transforms.Compose( [transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]) trainset = torchvision.datasets.CIFAR10(root='/datasets/cifar10/', train=True, download=False, transform=transform) trainloader = torch.utils.data.DataLoader(trainset, batch_size=128, shuffle=True, num_workers=2) classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck') criterion = nn.CrossEntropyLoss() ## compute loss surfaces ## fname = "high_loss_" + str(args.range) + "_" + str(args.n_pts) fname = fname.replace(".", "_") high_loss = get_loss_surface(evecs[:, -10:], model, trainloader, criterion, rng=args.range, n_pts=args.n_pts, use_cuda=use_cuda) torch.save(high_loss, fpath + fname) print("High Loss Done") fname = "low_loss_" + str(args.range) + "_" + str(args.n_pts) fname = fname.replace(".", "_") v1 = gram_schmidt(torch.randn(evecs.shape[0]).cuda(), evecs).unsqueeze(-1) v2 = gram_schmidt(torch.randn(evecs.shape[0]).cuda(), evecs).unsqueeze(-1) low_basis = torch.cat((v1, v2), -1) low_loss = get_loss_surface(low_basis, model, trainloader, criterion, rng=args.range, n_pts=args.n_pts, use_cuda=use_cuda) torch.save(low_loss, fpath + fname) print("Low Loss Done") fname = "full_loss_" + str(args.range) + "_" + str(args.n_pts) fname = fname.replace(".", "_") full_loss = get_loss_surface(torch.randn_like(low_basis).cuda(), model, trainloader, criterion, rng=args.range, n_pts=args.n_pts, use_cuda=use_cuda) torch.save(full_loss, fpath + fname) print("Full Loss Done")
def main(): global M, N, im im = parser(sys.argv[1]) #option = int(sys.argv[3]) goal = (1035, 910) # because the x,y pixel is x-column and y-row start = (144, 144) M, N = im.shape C = np.asarray(heuristic(sys.argv[2])) Astar(start, goal, C, im)
def define_price_max(self): spam_reader = parser(self.path) count = 0 for row in spam_reader: if float(row[self.price_position]) > self.prix_max: self.prix_max = float(row[self.price_position]) count += 1 if count == self.train_len: break
def run(): try: _preprocess() # video在运行程序之前是必须存在的,用户需要提供初始video # 可以在cfg.py里配置,没有配置的话,需要抛出异常 if not os.path.exists(videodir): raise Exception('video path not exists') # 开始主程序 print('开始解码原始视频...') parser() print('解码完毕,开始转码...') transfer() print('转码完毕,开始生成新视频...') generate_video(newdir) except Exception as e: print('失败: \n{}'.format(e)) else: print('视频转换成功')
def parser_helper(self , lfr_data_file ,iv_index_no , url_details): global url_count try: mutex.acquire() url_count += 1 mutex.release() #print url_details # Go to the start position of the url in data file lfr_data_file.seek(url_details[2]) #soup = BeautifulSoup(lfr_data_file.read(url_details[3])) url=url_details[0] page=lfr_data_file.read(url_details[3]) bufferpool=page+page+"1" x=(parser.parser(url, page, bufferpool, len(bufferpool)+1,len(page)+1)) z=str(url_count)+".txt" f5 = open("/home/viraj/NZ/NZParsed/"+z, 'w') count = 0 y=x[1].replace("\n"," ") y=y.split(' ') it=iter(y) for word,context in zip(it,it): count += 1 #print word+" "+context if self.check_word_sanity(word)== True: f5.write(word+" "+context+" "+str(url_count)+" "+str(count)+"\n") doc_to_url[url_count]= ( url , count, url_details[3]) f5.close() os.system("sort -T /home/viraj/NZ/temp/ -k1,1 -k3,3n -k4,4n /home/viraj/NZ/NZParsed/"+z+" -o /home/viraj/NZ/NZParsed/"+z) ''' if line=="\n": count+=1 x = line.replace("\n"," "+str(url_count)+" "+str(count)+"\n") f5.write(str(x)) doc_to_url[url_count]= ( url , count) soup = BeautifulSoup(lfr_data_file.read(url_details[3])) word_pos = 0 for string in soup.stripped_strings: for word in (words.rstrip(',.=?//\\!@#$%^&*()<>{}[]:\-_+~`";') for words in string.split() if len(words) in range(4,10)): # position of the word in the soup.stripped_strings word_pos += 1 # Check word sanity if self.check_word_sanity(word) == ' ':continue if word in word_dict: # Frequency count word_dict[word][0] += 1 else: # New discovered word word_dict[word] = [1 , list()] word_dict[word][1].append(word_pos) dic(str( word + str(word_dict[word] ) ) + '\n' )''' except: s3 = 'Error Index'+ str(iv_index_no) +':url '+ url_details[0] + '\n' dump(s3)
def start(self) : down=downloader(self._sitename,self._siteurl); if down.download(): parse=parser(down._save_location(),down._data_is(),self._siteurl) if parse.parse(): parse_links=parse.links_are(); parse_links=self.check_rel(parse_links,"http://"); self.remove_duplicate(1,parse_links); parse_img=parse.images_are(); self.remove_duplicate(2,parse_img);
def parse(self, msg): res = parser.parser(msg) if res[0]: self.srcNode = res[1] self.distNode = res[2] self.relayNode = res[3] self.msg = res[4] return True else: return False
def returner(bank,debug): messages = client.messages.list() for m in messages: if (m.direction == 'inbound' and debug == False): #you need to use m.from_ NOT m.From, this causes return parser(m.from_,m.body,bank) if (m.direction == 'inbound' and debug == True): #you need to use m.from_ NOT m.From, this causes keyword error return m.body
def main(): fr= FileReader(False) c=1 prog = re.compile(r'^[0-9]+_data') #to match index files for root, dirs, files in os.walk(fr.rootDirectory): for f in files: if prog.match(f): i=f.split('_')[0]+'_index' print("current Data file: "+os.path.join(root,f)+ "Size: "+str(c)) if c%5 == 0: #after reading every 5 data files write the data on hash table to temp index structure fr.writeToIndex() #break c=c+1 fr.f_html = gzip.open(os.path.join(root,f), 'rb') #open data_ file fr.f_index = gzip.open(os.path.join(root,i), 'rb') #open html_file for line in fr.f_index: try: _split = re.compile(r'[\0%s]' % re.escape('')) #remove \0 from file possible defect i_data=[] i_data=line.split() url = i_data[0] url = url.strip() html_str=fr.f_html.read(int(i_data[3])) # read html of the size[got from index] html_str=_split.sub('',html_str) if i_data[6] !='ok' and i_data[6] !='200': break pool=html_str+html_str+"123456"; p_tok_t=[] p_tok_t=parser.parser(urllib2.unquote(url), html_str,pool, len(html_str)+1,len(html_str)+1) #returns token p_tok=str(p_tok_t[1]).split('\n') no_words=0 fr.doc_id=fr.doc_id+1 tempHash={} for tok in p_tok: #porsess the tokens returned from file if fr.validToken(tok): fr.process_tok(tok.split(' ')[0],fr.doc_id,tempHash) no_words=no_words+1 fr.addToHash(fr.doc_id,tempHash) page = Page(url,no_words) fr.page_table[fr.doc_id]=page except TypeError,e: i_data=[] i_data=line.split() url = i_data[0] url = url.strip() print(url) fr.f_html.close() fr.f_index.close()
def run(self): os.system('clear') print "Acerque la targeta de la universidad al lector." nfc = NFC.NFC() # Bucle hasta la lectura de una targeta while True: #response = urllib2.urlopen('http://raiblax.com/pbe/receptor.php?id_alumno=FB68CCF1') response = nfc.read('http://raiblax.com/pbe/receptor.php?id_alumno=') if response != None: break; # Creacion del entorno grafico Menu = TestApp(parser(response),self).run()
def main(argv): if len(argv) >= 2: with open(argv[1], 'r') as f: grammar = read_bnf(f.read()) print_bnf(grammar) if len(argv) >= 3: tks = list(tokenizer(argv[1])) for tk in tks: print tk print ast = parser(tks) print ast
def run(self): while True: if len(_links)!=0: _down=downloader(self,self._sitename,_links.pop(0)); if _down.download(): _parse=parser(_down._save_location(),_down._data_is(),self._siteurl); if _parse.parse(): _parse_links=_parse.links_are(); elif len(_images)!=0: else: continue;
def __init__(self, command): if not config.read("muninrc"): raise ValueError("Found no configuration file.") self.server = config.get("Connection", "server") self.port = int(config.get("Connection", "port")) self.nick = config.get("Connection", "nick") self.user = config.get("Connection", "user") self.ircname = config.get("Connection", "name") self.client = connection(self.server, self.port) self.handler = parser(config, self.client,self) self.client.connect() self.run(command)
def load(filenames): agg = competitionAggregator() meetings = [] for filename in filenames: p=parser.parser() f = file(filename, "r") res = p.parse(f, filename) f.close() m = re.search("(\d+)-(\d+)", filename) date = float(m.groups(1)[0]) + float(m.groups(1)[1])/12 agg.add_results(res, date) meetings.append(filename) return agg.comps
def reconnect(self): """Reconnects to the server and reloads configuration, modules and self.msg_parser. """ self.send_data("QUIT :Reconnecting") self.close() self.config_reader = GeneralConfig() self.configuration = self.config_reader.read() self.msg_parser = parser.parser() self.registered = False self.first_msg = True self.channel_list = [] bot_module_functions.populate_ircchannels(self) self.connect_to_irc()
def typographicAnalyzeWorker(iq, oq): signal.signal(signal.SIGINT, signal.SIG_IGN) # Processes will receive SIGINT on Ctrl-C in main program. Just ignore it. for odtFilename, odtContent in iter(iq.get, "STOP"): resDict = {} odtFile = FileLike(odtContent) #FileLike provides seek() if zipfile.is_zipfile(odtFile): try: resDict = parser.parser(odtFile) except (parser.NumberingException, parser.NoAnswerException) as e: resDict["parsingException"] = str(e) print("Error parsing {}: {}".format(odtFilename, str(e))) else: resDict["error"] = "Not a valid zip file" print("ERROR: {} is not a valid zip file!".format(odtFilename)) odtFile.close() oq.put(resDict)
def parse_index_info(docid, data): vdata = [] for i in range(len(data)): page = data[i] page = "<p>" + page + "</p>" try: buf = page + page + '1' ret = parser.parser('', page, buf, 2 * len(page) + 1) vdata.append(ret[1]) if ret[0] <= 0: print("------------------------------------") except Exception as e: print('error') print(e) while 1:pass continue return blockmanage(docid, vdata)