def get_season(): url = f'{API_URL}/match_collections?statuses[]=waiting&' + \ f'tab=admin_created&type=fantasy&per_page=10&page=0' # seasons_data = ftStats.get_page_data(ftStats.get_html(url)) authorization = {'Authorization': 'Bearer fanteam undefined'} platform = Parser(url, authorization) seasons_data = platform.parserResult() # print(seasons_data) seasons = {} for item in seasons_data['seasons']: year = item.get('season') league = item.get('league')['name'] gameType = item.get('league')['gameType'] season_id = item.get('id') finalRound = item.get('finalRound') lastRound = item.get('lastRound') seasons.update({ season_id: { 'year': year, 'league': league, 'gameType': gameType, 'finalRound': finalRound, 'lastRound': lastRound } }) return seasons
class TestExpressions(unittest.TestCase): def setUp(self): self.parser = Parser() token_list = [] self.parser.load_tokens(token_list) def tearDown(self): pass def test_addition_expression(self): """5 + 5""" pass def test_subtraction_expression(self): """x := 5 - 5""" pass def test_division_expression(self): """x := 5 / 5""" pass def test_multiplication_expression(self): """x := 5 * 5""" pass
def run_data_parse(config): parse_config = config.get_configuration('parse') parser = Parser(config) if parse_config.get('parse'): parser.run_initial_parse() return parser
def getNews(): content = request.json if type(content) == dict: parser = Parser(content) response = parser.start() return jsonify(response) return bad_request('requested data types do not match')
def __init__(self, *args): self.staff_login = False gtk.Window.__init__(self) self.set_position(gtk.WIN_POS_CENTER) self.connect("destroy", self.do_quit) self.set_resizable(False) from modules.parser import Parser conf_parser = Parser() shoptitle = conf_parser.get_shop_name() self.set_title(shoptitle) # Top hbox layer self.loginLabel = gtk.Label(" Username: "******" Password: "******"Staff?") self.loginButton = gtk.Button("Login") self.loginButton.set_size_request(70, 30) self.registerButton = gtk.Button("Register") self.registerButton.set_size_request(70, 30) self.cancelButton = gtk.Button("Cancel") self.cancelButton.set_size_request(70, 30) #Signals self.checkbox.connect("toggled", self.on_checkButtonToggled) self.passwdInput.connect("activate", self.do_login) self.loginButton.connect("clicked", self.do_login) self.registerButton.connect("clicked", self.do_customer_register) self.cancelButton.connect("clicked", self.do_quit) #Layout self.table = gtk.Table() #Add elements to layout self.table.attach(self.loginLabel, 0, 2, 0, 1) self.table.attach(self.usernameInput, 2, 4, 0, 1) self.table.attach(self.passwdLabel, 4, 7, 0, 1) self.table.attach(self.passwdInput, 7, 9, 0, 1) self.table.attach(gtk.Label(), 0, 9, 1, 2) self.table.attach(self.checkbox, 0, 2, 2, 3) self.table.attach(self.loginButton, 6, 7, 2, 3) self.table.attach(self.registerButton , 7, 8, 2, 3) self.table.attach(self.cancelButton, 8, 9, 2, 3) self.add(self.table) self.show_all()
def main(kindOfSport='football', season_id=387, gameweek=6, skipNonPlaying=True, numTourn=176601, enableNumTourn=False): """Request information about the players. General request""" url = f'{API_URL}/seasons/{season_id}/players?season_id={season_id}&' + \ f'white_label=fanteam&round={gameweek}' # get_realPlayers(get_page_data(get_html(url)), kindOfSport, gameweek) authorization = {'Authorization': 'Bearer fanteam undefined'} platform = Parser(url, authorization) get_realPlayers(platform.parserResult(), kindOfSport, season_id, gameweek, skipNonPlaying, numTourn, enableNumTourn)
def get_ownership(realPlayerId, numTourn, gameweek, season_id): url = f'{API_URL}/real_players/{realPlayerId}?season_id={season_id}&' + \ f'round={gameweek}&tournament_id={numTourn}' authorization = {'Authorization': 'Bearer fanteam undefined'} plarform_player = Parser(url, authorization) data_player = plarform_player.parserResult() try: selectedRatio = data_player['tournamentPlayerStats'].get( 'selectedRatio') captainedRatio = data_player['tournamentPlayerStats'].get( 'captainedRatio') except AttributeError: selectedRatio, captainedRatio = ['', ''] return selectedRatio, captainedRatio
def parse_html(path): trie.empty() edge_list.clear() parser = Parser() html_paths = get_html_files(path) begin_time = time.time() for file in html_paths: print('Parsing file -- ' + file) links, words = parser.parse(file) for word in words: trie.add_word(word, file) for link in links: edge_list.append((file, link)) if html_paths: print("Direktorijum parsiran za %s sekundi" % (time.time() - begin_time))
def test_parser(): path = os.path.dirname(os.path.abspath(__file__)) + '/' fn_in = path + 'bubble_sort.txt' fs = FileSystem(file_name=fn_in) af = AsciiFilter(file_system=fs) ac = AsciiClassifier(ascii_filter=af) lc = LexicalClassifier(ascii_classifier=ac) lr = LexicalReclassifier(lexical_classifier=lc) pr = Parser(lexical_reclassifier=lr) fs = None af = None ac = None lc = None lr = None assert pr.parse()
def get_supported_apps(fix_only, custom_path=""): """Get a list of dict, a dict for each supported application.""" if len(fix_only) != 0: database_files = [] for db_file in fix_only: db_file = "{0}{1}.json".format(DB_FOLDER, db_file) if path.exists(db_file): database_files.append(db_file) else: database_files = glob("{0}*.json".format(path.join(DB_FOLDER, ""))) if len(fix_only) > 1 and custom_path: exit("You can't use --path with more than application at once.") database_files.sort() supported_apps = [] for db_file in database_files: application_data = Parser(db_file, args) if application_data.is_installed(): supported_apps.append(application_data.get_application()) return supported_apps
def collect(self) -> Dict[SourceSite, List[MetaArticle]]: res = {} threads = [] for source, parser in self.parsers.items(): articles = [] keywords = [] rss = [] parsed_articles = parser.parse() # Start new parser for each Parser for rss_article in parsed_articles: html_parser = Parser(rss_article) t = MyThread(html_parser, rss_article) threads.append(t) t.start() # Join threads for t in threads: t.join() # Get results from threads for t in threads: keywords.append(t.result) rss.append(t.rss) for i, rss_article in enumerate(parsed_articles): meta_article = MetaArticleFactory.from_rss_article(rss_article) # Match the right keywords for right article for i, rs in enumerate(rss): if rs == rss_article: meta_article.keywords += keywords[i] articles.append(meta_article) res[source] = articles return res
def setUp(self): raw = Opener.open_file('1') self.kakuro = Parser.parse(raw)
def parse(self): logging.info('Parsing data started') parser = Parser(self.current_directory) parser.extract_grob() parser.extract_fein() logging.info('Parsing data finished')
def main(): urls = TOURNAMENTS_URL.split(', ') for url in urls: tournament = Parser(url) get_pageData(tournament.parserResult())
def setUp(self): self.parser = Parser() token_list = [] self.parser.load_tokens(token_list)
if DEBUG: test_id = '14' # Redni broj test primera [01-15] path_root = './' args = {} args['src'] = f'{path_root}{test_id}/src.pas' # Izvorna PAS datoteka args['gen'] = f'{path_root}{test_id}/gen.c' # Generisana C datoteka else: import argparse arg_parser = argparse.ArgumentParser() arg_parser.add_argument('src') # Izvorna PAS datoteka arg_parser.add_argument('gen') # Generisana C datoteka args = vars(arg_parser.parse_args()) with open(args['src'], 'r') as source: text = source.read() lexer = Lexer(text) tokens = lexer.lex() parser = Parser(tokens) ast = parser.parse() # grapher = Grapher(ast) # grapher.graph() symbolizer = Symbolizer(ast) symbolizer.symbolize() generator = Generator(ast) generator.generate(args['gen']) runner = Runner(ast) runner.run() # ACINONYX - END
def main(input): infiles = [] # determine if the inputs is a directory or vmfile if re.search("\.vm$", input): # input is a single .vm file infiles.append(input) output = input.strip(".vm") output = "{}.asm".format(output) else: # input is a directory # output file name should be <dirname>.asm located in that directory try: files = os.listdir(input) for f in files: if re.search("\.vm$", f): infiles.append(os.path.join(input, f)) # generate output filename input = re.sub("/$", "", input) output = os.path.join(os.path.abspath(input), "{}.asm".format(os.path.split(input)[1])) except Exception as e: print("Error attempting to read directory: {}".format(e)) exit(1) # if empty, output error and exit if not infiles: print("No files found with .vm suffix in {} directory. Exiting".format( input)) exit(1) # single code generator for all vm files, single ASM output code_gen = CodeGenerator() asm_output = code_gen.generate_init() #asm_output = [] # loop through all .vm files for file in infiles: # open and load the file into a list vm_input = [] with open(file) as f: vm_input = f.readlines() vmfile = file.strip(".vm") vmfile = os.path.split(vmfile)[-1] # each vm file gets its own parser parser = Parser(vm_input) while parser.has_more_commands(): # set vmfile name, used to generate static variable symbols code_gen.vmfile = vmfile parser.advance() try: if parser.command_type() is config.C_EMPTY_LINE: # skip whitespace/blank lines continue elif parser.command_type() in config.PUSH_POP_COMMANDS: asm_output.extend( code_gen.generate_push_pop(parser.command_type(), parser.arg1(), parser.arg2())) elif parser.command_type() == config.C_ARITHMETIC: asm_output.extend( code_gen.generate_arithmetic(parser.arg1())) elif parser.command_type() == config.C_LABEL: asm_output.extend(code_gen.generate_label(parser.arg1())) elif parser.command_type() == config.C_GOTO: asm_output.extend(code_gen.generate_goto(parser.arg1())) elif parser.command_type() == config.C_IF: asm_output.extend(code_gen.generate_if(parser.arg1())) elif parser.command_type() == config.C_FUNCTION: asm_output.extend( code_gen.generate_function(parser.arg1(), parser.arg2())) elif parser.command_type() == config.C_CALL: asm_output.extend( code_gen.generate_call(parser.arg1(), parser.arg2())) elif parser.command_type() == config.C_RETURN: asm_output.extend(code_gen.generate_return()) except ParseError as err: print( "Parser error. Expression: <{}>. Error detail: {}".format( err.expression, err.message)) exit(1) except CodeError as err: print( "Code generator error. Expression: <{}>. Error detail: {}". format(err.expression, err.message)) exit(1) # write out asm file with open(output, "w") as f: for line in asm_output: f.write(line) f.write("\n")
def run_parser(): last_upload = get_last_upload() p = Parser(last_upload.upload_content) p.loop_payments() return 'parsing complete'
def setUp(self): """set up the parser and a whole bunch of mock tokens to be run by the parser""" self.parser = Parser() pass
def _initialize_all_modules(self): self.scanner = Scanner(self.source_file) self.parser = Parser() self.v_runtime = VirtualRunTime()
from modules.scanner import Scanner from modules.parser import Parser from sys import argv, exit if len(argv) == 1: exit('No arguments provided. Need to provide text file as argument.') elif len(argv) > 2: exit('Too many arguments.') if str(argv[1]).split('.')[-1] != 'txt': exit('Wrong file format. File must be a TXT file') file = open(argv[1]) with file as input_file: file_content = input_file.read() scanner = Scanner(file_content) parser = Parser(scanner) parser.start()
def setUp(self): raw = Opener.open_file('..\\modules\\fields\\1') self.kakuro = Parser.parse(raw)
def main(infile): # read the input file into a list, remove whitespace input = [] binary_lines = [] with open(infile) as f: input = f.readlines() # first pass, build symbol table parser = Parser(input) symbol_table = SymbolTable() rom_addr = 0 while parser.has_more_commands(): parser.advance() try: if parser.command_type( ) == parser.C_COMMAND or parser.command_type() == parser.A_COMMAND: rom_addr += 1 elif parser.command_type() == parser.L_COMMAND: symbol = parser.symbol() symbol_table.add_entry(symbol, rom_addr) except ParseError as err: print("Parser error. Expression: {}. Error detail: {}".format( err.expression, err.message)) exit(1) # second pass parser = Parser(input) ram_addr = 16 while parser.has_more_commands(): parser.advance() try: if parser.command_type() == parser.A_COMMAND: symbol = parser.symbol() try: # if the symbol is a constant (int), translate it int_symbol = int(symbol) binary_lines.append(translate_a_instruction(int_symbol)) except ValueError: # symbol is not an integer, so either look it up, or its a new variable if symbol_table.contains(symbol): binary_lines.append( translate_a_instruction( symbol_table.get_address(symbol))) else: symbol_table.add_entry(symbol, ram_addr) binary_lines.append(translate_a_instruction(ram_addr)) ram_addr += 1 elif parser.command_type() == parser.C_COMMAND: # Translate C command binary_lines.append( translate_c_instruction(parser.comp(), parser.dest(), parser.jump())) except ParseError as err: print("Parser error. Expression: {}. Error detail: {}".format( err.expression, err.message)) exit(1) # translation is done. output to new .hack file outfile = infile.replace(".asm", "") outfile = "{}.hack".format(outfile) with open(outfile, "w") as f: for line in binary_lines: f.write(line) f.write("\n")
import os from werkzeug import security from flask import Flask, Request, Response, render_template, request, redirect, url_for UPLOAD_FOLDER = 'uploads' ALLOWED_EXTENSIONS = set(['txt', 'py']) application = app = Flask(__name__) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER from modules.parser import Parser parser = Parser() def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS @app.route("/", methods=['GET', 'POST']) def first(): if request.method == 'POST': file_func = request.files['file'] if file_func and allowed_file(file_func.filename): filename = file_func.filename file_func.save(os.path.join(app.config['UPLOAD_FOLDER'],filename)) return redirect('/')