Best Python code snippet using avocado_python
newsletter.py
Source:newsletter.py
...53 def get_total_contacts(self,obj):54 return obj.total_subscribers()55 get_total_contacts.short_description = 'Total contacts' 56 57 def get_colored_status(self,obj):58 s = "<div style='color: #ffffff; font-weight:bold; padding: 3px; background:%s'>"+obj.get_status_display()+"</div>" 59 if obj.status == Newsletter.DRAFT :60 return s % "#e9e9e9;";61 elif obj.status == Newsletter.WAITING :62 return s % "#07ccf0;";63 elif obj.status == Newsletter.CANCELED :64 return s % "red;";65 elif obj.status == Newsletter.SENDING :66 return s % "#a9c47d;";67 else: 68 return s % "green;"; 69 get_colored_status.short_description = _("Status")70 get_colored_status.allow_tags = True 71
...
robinhood.1m.py
Source:robinhood.1m.py
...11GREEN = '\033[32m'12RED = '\033[1;31m'13DEFAULT_COLOR = '\033[0m'14FONT = "| font='Menlo'"15def get_colored_status(change):16 status = ''17 if change < 0:18 status = RED + 'â¼'19 elif change > 0:20 status = GREEN + 'â²'21 return status22def return_equity_and_market_value():23 portfolio = r.profiles.load_portfolio_profile()24 current_value = portfolio['equity']25 open_value = portfolio['equity_previous_close']26 change = float(current_value) - float(open_value)27 change_in_percentage = change / float(open_value) * 10028 status = get_colored_status(change)29 total_change_info = "{:,.2f} {} {:,.2f}({:.2f}%)" + DEFAULT_COLOR30 print(total_change_info.format(float(current_value), status,31 abs(float(change)), change_in_percentage))32 return float(portfolio["equity"]), float(portfolio["market_value"])33def show_postions_as_list(equity, market_value):34 # Use '---' to represent the list will show below.35 print("---")36 stock_info = "{:<10} {:<10} {:<10} {:<20}" + DEFAULT_COLOR + FONT37 print(stock_info.format("Symbol", "Equity", "Allocation", "Total"))38 my_stocks = r.account.build_holdings()39 cash_position = round(equity - market_value, 2)40 cash_percentage = round(cash_position / equity * 100, 2)41 for stock_name, values in sorted(my_stocks.items(),42 key=lambda kv: float(kv[1]["percentage"]),43 reverse=True):44 total_change = float(values["percent_change"])45 status = get_colored_status(total_change)46 change_with_status = status + " " + str(abs(total_change)) + "%"47 allocation = round(float(values["equity"]) / equity * 100, 2)48 print(stock_info.format(stock_name, values["equity"],49 str(allocation) + "%", change_with_status))50 print(stock_info.format("Cash", str(cash_position),51 str(cash_percentage) + "%", "---"))52def main():53 username = "<YOUR_ROBINHOOD_USERNAME>"54 password = "<YOUR_ROBINHOOD_PASSWORD>"55 r.login(username, password)56 equity, market_value = return_equity_and_market_value()57 show_postions_as_list(equity, market_value)58if __name__ == '__main__':59 main()
obsstatus
Source:obsstatus
...44 arch = fields[1]45 status = fields[2]46 data[distro][arch] = status47 return data48def get_colored_status(arch, status):49 try:50 color = COLORS[status]51 except KeyError:52 color = 'yellow'53 return colored(arch, color=color)54def tabulate_prj_data(prj_data):55 watches = prj_data.keys()56 headers = ['Distro'] + ['\n'.join(watch) for watch in watches]57 statuses = defaultdict(dict) # distro: {watch1: data}58 for watch, distro_data in prj_data.items():59 for distro, arch_data in distro_data.items():60 arch_statuses = []61 for arch, status in arch_data.items():62 arch_statuses.append(get_colored_status(arch, status))63 statuses[distro][watch] = arch_statuses64 distros = sorted(statuses.keys())65 rows = []66 for distro in distros:67 row = [distro]68 for watch in watches:69 try:70 text = ' '.join(statuses[distro][watch])71 except KeyError:72 text = ''73 row.append(text)74 rows.append(row)75 return tabulate(rows, headers, tablefmt='fancy_grid')76def print_prj_status(watches):...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!