How to use strip_strs method in lisa

Best Python code snippet using lisa_python

Scrape_All_UFCStats.py

Source:Scrape_All_UFCStats.py Github

copy

Full Screen

...44 list of str45 list of desired attributes.46 """47 return list(map(lambda line: line[attr], link_soup))48def strip_strs(str_list):49 """Strip list of strings of leading and trailing whitespace.50 Parameters51 ----------52 str_list : list53 List of strings.54 Returns55 -------56 list of str57 """58 return list(map(lambda x: x.text.strip(), str_list))59def get_ufcstats_event_links(stats_link="http://ufcstats.com/statistics/events/completed?page=all"):60 """Retrieve html, parse html for event links, and return links.61 Note that no data exists for UFC 1.62 Parameters63 ----------64 stats_link : str, optional65 Assuming the domain for UFCStats will not change66 Returns67 -------68 list of str69 List of urls to all events70 Notes71 -----72 The function returns the next upcoming event.73 """74 soup = get_soup(stats_link)75 matchup_links = soup.select("i.b-statistics__table-content > a[href]")76 matchup_links = get_attribute_list(matchup_links, 'href')77 return matchup_links78def get_ufcstats_matchup_links(ufcstats_event_url):79 """Retrieve and parse html for matchup urls for event80 Parameters81 ----------82 ufcstats_event_url : str83 Returns84 -------85 matchup_links : list86 list of url strings87 event_dict : dict88 Info for entire event89 """90 soup = get_soup(ufcstats_event_url)91 matchup_links = soup.select("tbody.b-fight-details__table-body > tr[data-link]")92 matchup_links = get_attribute_list(matchup_links, 'data-link')93 event_name = soup.select("body > section > div > h2 > span")94 event_info = soup.select("div.b-list__info-box.b-list__info-box_style_large-width > ul > li")95 event_name = event_name[0].text.strip()96 event_date = event_info[0].text.split(':')[1].strip()97 event_location = event_info[1].text.split(':')[1].strip()98 fight_count = len(matchup_links)99 event_dict = {'EventName': event_name,100 'EventDate': event_date,101 'EventLocation': event_location,102 'EventURL': ufcstats_event_url,103 'FightCount': fight_count}104 print(event_name, event_date, event_location)105 return matchup_links, event_dict106def parse_ufcstats_matchup(matchup_link):107 """Parse matchup html for info on fighters.108 Parameters109 ----------110 matchup_link : str111 url to matchup112 Returns113 -------114 dict115 """116 soup = get_soup(matchup_link)117 fighter_links = soup.select("h3.b-fight-details__person-name > a[href]")118 fighter_links = get_attribute_list(fighter_links, 'href')119 fighter_names = soup.select("h3.b-fight-details__person-name > a")120 fighter_names = strip_strs(fighter_names)121 nicknames = soup.select("div.b-fight-details__persons.clearfix > div.b-fight-details__person > div > p")122 nicknames = strip_strs(nicknames)123 outcomes = soup.select("div.b-fight-details__persons.clearfix > div.b-fight-details__person > i")124 outcomes = strip_strs(outcomes)125 bout_type = soup.select("div.b-fight-details__fight > div.b-fight-details__fight-head > i")126 special_bouts = bout_type[0].select('img')127 title_bout = False128 bonus = ''129 if special_bouts:130 for s in special_bouts:131 special_png_name = s['src'].split('/')[-1]132 if special_png_name == 'belt.png':133 title_bout = True134 elif special_png_name == 'perf.png':135 bonus += 'perf '136 elif special_png_name == 'fight.png':137 bonus += 'fight '138 elif special_png_name == 'sub.png':139 bonus += 'sub '140 elif special_png_name == 'ko.png':141 bonus += 'ko '142 perf_bonus = True if bonus else False143 bout_type = strip_strs(bout_type)[0]144 method = soup.select("div.b-fight-details__fight > div.b-fight-details__content > p:nth-child(1) > "145 "i.b-fight-details__text-item_first > i:nth-child(2)")146 method = strip_strs(method)[0]147 round_seen = soup.select(148 "div.b-fight-details__fight > div.b-fight-details__content > p:nth-child(1) > i:nth-child(2)")149 round_seen = round_seen[0].text.split('Round:')[1].strip()150 round_time = soup.select(151 "div.b-fight-details__fight > div.b-fight-details__content > p:nth-child(1) > i:nth-child(3)")152 round_time = round_time[0].text.split('Time:')[1].strip()153 round_format = soup.select(154 "div.b-fight-details__fight > div.b-fight-details__content > p:nth-child(1) > i:nth-child(4)")155 round_format = round_format[0].text.split(':')[1].strip()156 referee = soup.select(157 "div.b-fight-details__fight > div.b-fight-details__content > p:nth-child(1) > i:nth-child(5) > span")158 referee = strip_strs(referee)[0]159 details = soup.select("div.b-fight-details__fight > div.b-fight-details__content > p:nth-child(2)")160 details = details[0].text.split('Details:')[1].strip()161 # TOTALS162 fighter_totals = soup.select("body > section > div > div > section:nth-child(4) > table > tbody > tr")163 round_totals = soup.select("body > section > div > div > section:nth-child(5) > table > tbody")164 fighter_strike_totals = soup.select("body > section > div > div > table > tbody > tr")165 round_strike_totals = soup.select("body > section > div > div > section:nth-child(8) > table > tbody")166 # check that data for rounds is available167 if round_totals:168 round_numbers = strip_strs(round_totals[0].select('th'))169 number_rounds_needed = len(round_numbers)170 subtotals = fighter_totals[0].select('td')171 round_subtotals = round_totals[0].select('td')172 strike_subtotals = fighter_strike_totals[0].select('td')173 round_strike_subtotals = round_strike_totals[0].select('td')174 fighter_0 = []175 fighter_1 = []176 fighter_0_rounds = []177 fighter_1_rounds = []178 fighter_0_strike_rounds = []179 fighter_1_strike_rounds = []180 for sub in subtotals + strike_subtotals:181 sub_p = sub.select('p')182 fighter_0.append(sub_p[0].text.strip())...

Full Screen

Full Screen

feature.py

Source:feature.py Github

copy

Full Screen

1import functools as fts2import itertools as its3import os4import re5from io import StringIO6from pathlib import Path7import click8import sh9import toolz.functoolz as ftz10import toolz.itertoolz as itz11from sh.contrib import git12from toolz.curried import filter, map13@click.command()14@click.option(15 "--branch", "-b", help="Default = HEAD. Specify a branch to get children for."16)17@click.option(18 "--recursive/--no-recursive",19 "-r/-R",20 help="Recursively include children of children.",21)22@click.option(23 "--show-upstream/--no-show-upstream",24 "-u/-U",25 help="Show the upstream for each branch, a space, then the branch itself.",26)27def descendants(branch, recursive, show_upstream):28 """29 USAGE30 git-children [--[no]-show-upstream] [--[no]-recursive] [--branch=<branch>]31 DESCRIPTION32 Show the children of this branch. Can recursively show descendents as33 well. Can also show "upstream branch" format, suitable for piping to ``tsort``.34 """35 git_rev_parse = sh.Command("git-rev-parse")36 git_children = git_rev_parse.bake("--abbrev-ref", "HEAD")37 strip_upstreams = map(lambda x: x[1])38 if not branch:39 branch = str(git_children()).strip()40 def get_children(branch):41 git_upstreams = git.branch.bake("--format=%(upstream) %(refname)", "--list")42 strip_strs = map(lambda x: x.strip())43 make_pairs = map(lambda x: tuple(x.split(" ")))44 keep_heads = filter(lambda x: re.match("refs/heads", x[1]))45 strip_branch_refs = map(lambda x: tuple([x[0], re.sub("refs/.*?/", "", x[1])]))46 strip_upstream_refs = map(47 lambda x: tuple([re.sub("refs/.*?/", "", x[0]), x[1]])48 )49 keep_referrents = filter(lambda x: str(branch) == x[0])50 compute_branches = ftz.compose(51 keep_referrents,52 strip_upstream_refs,53 strip_branch_refs,54 keep_heads,55 make_pairs,56 strip_strs,57 )58 return [x for x in compute_branches(git_upstreams())]59 def get_all_children(branch):60 children = get_children(branch)61 return list(itz.mapcat(get_all_children, strip_upstreams(children))) + children62 branches = get_all_children(branch) if recursive else get_children(branch)63 for (upstream, ref) in branches:64 if show_upstream:65 print(f"{upstream} {ref}")66 else:67 print(ref)68 return 069@click.command()70@click.option(71 "-t",72 "--ticket",73 help="Specify the JIRA ticket to use.",74 default=lambda: os.environ.get("CURRENT_JIRA_TASK", ""),75 prompt=True,76 show_default="CURRENT_JIRA_TASK",77)78@click.option(79 "-p",80 "--project-directory",81 help='Specify the directory "tag" in which "git into" will look.',82 default=lambda: Path.cwd().name,83 prompt=True,84 show_default="current directory",85)86@click.option(87 "-n",88 "--name",89 help="Specify the phrase that describes this feature's reason to exist.",90 default=lambda: os.environ.get("CURRENT_JIRA_DESC", "Senseless change for no good reason."),91 prompt=True,92 show_default="CURRENT_JIRA_DESC",93)94def feature(ticket, project_directory, name):95 """96 USAGE97 git-feature <ticket> <project folder> <name>98 DESCRIPTION99 Create a new GIT branch, tracking master, and setting upstream, named100 following the pattern 'feature/<ticket>__<project folder>__<name>'. Other git-tools tools101 will look for names following this pattern. Spaces in <name> will be replaced with dashes.102 """103 name__interspersed_dashes = "-".join(re.split(r"\s+", name))104 br_name = f"feature/{ticket}__{project_directory}__{name__interspersed_dashes}"105 click.echo(f"Calling git-feature to create {br_name}")106 try:107 print(git.checkout("master", _err_to_out=True))108 print(sh.jira.view(ticket))109 print(git.checkout("-t", "-b", br_name, _err_to_out=True))110 print(git.branch("--set-upstream-to=master", _err_to_out=True))111 except sh.ErrorReturnCode as e:112 click.echo(f"Something went wrong!\n\nException: {e}")113 return 1114 return 0115@click.command()116@click.option(117 "--name", "-n", help='The name of the branch to finish. Must start with "feature/".'118)119def finish(name):120 """121 USAGE122 git-finish [-n/--name= <name>]123 DESCRIPTION124 Set the current branch's upstream to point to old, then rename it,125 substituting the "feature" prefix for "old", so it no longer appears in126 "git features".127 """128 buf = StringIO()129 if not name:130 name = str(git.branch("--show-current")).strip()131 if re.match("^feature/", name):132 new_name = re.sub("^feature", "finished", name)133 click.echo(f"Finishing {name} by renaming it to {new_name}")134 try:135 git.branch(u="old", _err_to_out=True, _out=buf)136 git.branch("-m", name, new_name, _err_to_out=True, _out=buf)137 git.checkout("master")138 except sh.ErrorReturnCode:139 click.echo("Something went wrong!")140 click.echo(buf.getvalue())141 return 1142 else:143 click.echo('Branch name does not start with "feature/"')144 return 1...

Full Screen

Full Screen

1905c-李超超.py

Source:1905c-李超超.py Github

copy

Full Screen

1'''2"""# 使用if~编写程序~实现以下功能3"""4从键盘获取用户名、密码5如果用户名和密码都正确(预先设定一个用户名和密码),那么就显示“欢迎进入xxx的世界”,6否则提示密码或者用户名错误7"""8username = input("请输入用户名:")# 用户名9pwd = input("请输入密码:")# 密码10# 检验不能为空11if username and pwd:12 # 判断用户名,密码是否正确13 if username=="lcc" and pwd=="123":14 print("欢迎进入xxx的世界")15 else:16 print("密码或者用户名错误")17else:18 print("不能为空")19"""20使用while,完成以下图形的输出21"""22i = 123while i<=5:24 a = i * "*"25 print(a)26 i +=127i = 128while i<=4:29 a = 530 a-=i31 print(a*"*")32 i+=133'''34"""35strs = "i love beijing"36kg = ""37print(strs.capitalize())#首字母大写38print(strs.title())#每个首字母大写39print(strs.lower())#全小写40print(strs.upper())#全大写41print(strs.startswith("i"))#判断开头42print(strs.endswith("beijing"))#全大写43up_strs = strs.partition("love")44print(up_strs)#切成三部分45str_kg = kg.join(up_strs)46print(str_kg)#将元组转换成字符串47print(strs.splitlines())# 将字符串转化成列表48strs_nt = "\n\t I love you\t\n"49strip_strs = strs_nt.strip()#去空格字符50print(strip_strs)51"""52def month_day(month,day):53 month=int(month)54 day= input((day))55 return month,day...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful