def year_string(self) -> str: """Return a string representation of the datetime's year.""" if self.year_bce: if self.use_ybp: # YBP dates ybp, humanized_ybp = self.year_bp, None if ybp >= MILLIFICATION_FLOOR: humanized_ybp = millify(ybp, precision=self.significant_figures) elif ybp >= PRETTIFICATION_FLOOR: humanized_ybp = prettify(ybp) else: humanized_ybp = ybp year_string = f'c. {humanized_ybp} YBP' else: # BCE dates prettify_circa_year = (self.year_bce >= PRETTIFICATION_FLOOR and self.year_bce >= BCE_CIRCA_FLOOR) if prettify_circa_year: year_string = f'c. {prettify(self.year_bce)}' elif self.year_bce >= PRETTIFICATION_FLOOR: year_string = f'{prettify(self.year_bce)}' else: year_string = f'{self.year_bce}' year_string = f'{year_string} BCE' else: # CE dates year_string = str(self.year) return year_string
def create_embed(data, flag, title, day, time): embed = discord.Embed( colour=discord.Colour.purple(), title=title + " Covid-19 " + day, url="https://www.worldometers.info/coronavirus/") embed.set_thumbnail(url=flag) if time < 1: embed.set_footer(text="Updated less than a min. ago") else: embed.set_footer(text="Updated " + str(time) + "min ago") todayCases = prettify(data['todayCases']) todayDeaths = prettify(data['todayDeaths']) todayRecovered = prettify(data['todayRecovered']) activeCases = millify(data['active'], precision=2) population = millify(data['population'], precision=2) totalCases = millify(data['cases'], precision=2) tests = millify(data['tests'], precision=2) recovered = millify(data['recovered'], precision=2) totalDeaths = millify(data['deaths'], precision=2) embed.add_field(name="<:casesarrow:696516134962462771> New Cases", value=todayCases) embed.add_field(name="<:deathsarrow:696493553697947690> New Deaths", value=todayDeaths) embed.add_field(name="⛑️ New Recoveries", value=todayRecovered) embed.add_field(name="<:totalcases:696506315131846717> Total Cases", value=totalCases + " **({:.2f}%)**".format(calc_percentage(data['cases'], data['population'])) ) embed.add_field(name="<:coronadeaths:696408166988120124> Total Deaths", value=totalDeaths + " **({:.2f}%)**".format(calc_percentage(data['deaths'], data['cases'])) ) embed.add_field(name="<:coronarecovered:696408101078827049> Total Recovered", value=recovered + " **({:.2f}%)**".format(calc_percentage(data['recovered'], data['cases'])) ) embed.add_field(name="<a:coronacases:696408215675732078> Active Cases", value=activeCases + " **({:.2f}%)**".format(calc_percentage(data['active'], data['population'])) ) embed.add_field(name="🧪 Tests", value=tests) embed.add_field(name="<:coronapopulation:813592002293792788> Population", value=population) return embed
def get_tr(self, value, column_name, color_class, num): # first make a row with the title of the value. if column_name is None: title = str(value.name.title()) if "Dkk" in title: title = title.replace("Dkk", "DKK") if "Eur" in title: title = title.replace("Eur", "EUR") if "Usd" in title: title = title.replace("Usd", "USD") if "*" in title: title = title.replace(" *", "") title = " " + title rows = [ html.Th([ html.I( "lens", className=f"tiny material-icons {color_class[num]}"), title ], scope='row', className='table-th') ] else: title = " " + str(column_name[self.title_num]) rows = [ html.Th([ html.I( "lens", className=f"tiny material-icons {color_class[num]}"), title ], scope="row", className="table-th") ] # what values to get. Default is -1, so it gets the latest value. num = self.startrow # makes row for every column. for i in range(self.columns): # get the rows value. val = str(value.get_values()[num]) if val == "*": val = "-" else: val = millify.prettify(val) rows.append(html.Td(val)) num -= 1 tr = html.Tr(rows) self.title_num += 1 return tr
async def execute(self, args, msg): key = globals.bot.conf.get(globals.bot.conf.keys.GMAPS_API_KEY, bypass_protected=True) if key is None: raise RuntimeError('Google maps API key not set.') query = ' '.join(args) res = covid19.data(query, key=key) colour = globals.bot.conf.get(globals.bot.conf.keys.EMBED_COLOUR) embed = discord.Embed(title=f'COVID-19 data for {res.region or query}', color=colour) embed.add_field(name='Total Cases', value=prettify(res.cum_cases)) embed.add_field(name='Total Deaths', value=prettify(res.cum_deaths)) if res.pop is not None: embed.add_field(name='Population', value=millify(res.pop, precision=2)) embed.add_field(name='7 day average cases per million', value=f'{res.sda_cpm: .2f}') embed.add_field(name='7 day average deaths per million', value=f'{res.sda_dpm: .2f}') source = f'[{res.source}]({res.source_url})' if res.source_url else res.source embed.add_field(name='Source', value=source) dfm = res.df.rolling(7, on='date').mean() p = dfm.plot(x='date', y='new_cases', kind='line', grid=True, figsize=(7.5, 4.1), color='#a6ce86', legend=False) p.set_facecolor('#2f3136') p.get_figure().set_facecolor('#2f3136') xticks = list(dfm.date[::len(dfm.date) // 8]) if type(xticks[0]) == str: xlabels = list( map(lambda e: datetime.datetime.strptime(e, '%Y-%m-%d').date(), xticks)) xticks = range(0, len(dfm.date), len(dfm.date) // 8) else: xlabels = xticks p.set_xticks(xticks) p.set_xticklabels(map(lambda e: e.strftime('%Y-%m-%d'), xlabels), rotation=25) p.get_figure().subplots_adjust(top=0.95, bottom=0.16, right=0.98, left=.11) for spine in p.spines.values(): spine.set_color('#b0b0b0') p.xaxis.label.set_color('white') p.set_ylabel('new cases (7 day average)', color='white') p.tick_params(axis='x', colors='white', labelrotation=15) p.tick_params(axis='y', colors='white') p.title.set_color('white') out_file = io.BytesIO() plt.savefig(out_file) plt.close() out_file.seek(0) region = re.sub(r'[^a-zA-Z0-9_]+', '_', res.region).strip('_') file = discord.File(out_file, filename=f'{region}.png') embed.set_image(url=f'attachment://{region}.png') await msg.channel.send(file=file, embed=embed)
def table_keystats(stock): # Getting the data eps, payout_ratio, book_value_per_share, free_cash_flow, free_cash_flow_per_share = stock.get_financials( ) # getting EPS, Payout ratio, Book value per share, Free cash flow, Free cash flow per share del free_cash_flow # we don't want to include this one. pe = stock.calc_pe_ratio(eps) # get P/E ratio shares = stock.get_number_of_shares() # getting amount of shares returns = stock.stock_growth() if returns == "*": return_1yr = "-" elif "1y" in returns: return_1yr = returns["1y"] # 1 yeah stock price return return_1yr = f"{round(return_1yr, 2)}%" else: return_1yr = "-" if stock.past_prices_close == "*": price_latest = "-" volume_avg_30day = "*" else: price_latest = stock.past_prices_close['Current'] # latest close price price_latest = round(float(price_latest), 3) volume_avg_30day = stock.calc_avg_volume( 22 ) # 30 day average stock trading volume (22 trading days in a month) if "," in str(shares['TTM']): shares_ttm = shares['TTM'].replace(",", "") else: shares_ttm = shares['TTM'] if "," in str(shares[-2]): shares_2 = shares[-2].replace(",", "") else: shares_2 = shares[-2] if type(shares_ttm) is str and shares_ttm != "*": shares_ttm = float(shares_ttm) else: shares_ttm = shares_ttm if type(shares_2) is str and shares_2 != "*": shares_2 = float(shares_2) else: shares_2 = shares_2 if shares_ttm == 0 or np.isnan(shares_ttm): if shares_2 == 0 or np.isnan(shares_2): marketcap = "-" shares = "-" else: marketcap = price_latest * float(shares_2) * 1000000 marketcap = f"{millify.millify(marketcap, precision=2)} {stock.stock_currency}" shares = shares_2 * 1000000 shares = millify.millify(shares, precision=2) elif price_latest == "-": marketcap = "-" else: marketcap = price_latest * float( shares_ttm) * 1000000 # calculating market cap marketcap = f"{millify.millify(marketcap, precision=2)} {stock.stock_currency}" shares = shares_ttm * 1000000 shares = millify.millify(shares, precision=2) if ".0" in str(price_latest)[-2:]: price_latest = str(price_latest).replace(".0", "") if volume_avg_30day == "*": volume_avg_30day = "-" # Error getting volume else: volume_avg_30day = millify.prettify(round(volume_avg_30day, 0)).replace(".0", "") def get_pdseries_html_row(pd_series): if type(pd_series["TTM"]) is str and pd_series['TTM'] != "*": pd_series_ttm = float(pd_series["TTM"]) else: pd_series_ttm = pd_series["TTM"] if pd_series_ttm == "*" or np.isnan(pd_series_ttm): # no data for ttm # bad data check if type(pd_series[-2]) is str and pd_series[-2] != "*": pd_series_2 = float(pd_series[-2]) else: pd_series_2 = pd_series[-2] if pd_series_2 == "*" or np.isnan( pd_series_2 ): # no data in latest period either. We can't use this data. value = "-" # null value name = pd_series.name else: # use from newest annual period value = pd_series_2 name = pd_series.name + " (" + pd_series.index[-2] + ")" else: # use from TTM value = pd_series_ttm name = pd_series.name + " (TTM)" if " *" in name: name = name.replace(" *", "") if value != "-": value = millify.millify(value, precision=2) if " %" in name: name = name.replace(" %", "") if value != "-": value = str(value) + "%" if " EUR" in name: name = name.replace(" EUR", "") if value != "-": value = str(value + " EUR") if " DKK" in name: name = name.replace(" DKK", "") if value != "-": value = str(value + " DKK") if " USD" in name: name = name.replace(" USD", "") if value != "-": value = str(value + " USD") html_row = [ html.Td([name]), html.Td([value], className="right-align bold") ] return html_row if type(pe) is str: pe = "-" else: pe = round(pe, 2) # creating html for table table = html.Table( [ html.Tbody([ html.Tr([ # P/E row html.Td(["P/E Ratio"]), html.Td([pe], className="right-align bold") ]), html.Tr([ # Latest price row html.Td(["Latest Price"]), html.Td([f"{price_latest} {stock.stock_currency}"], className="right-align bold") ]), html.Tr([ # Average 30-day volume row html.Td(["30-Day Avg Daily Volume"]), html.Td([volume_avg_30day], className="right-align bold") ]), html.Tr([ # Market cap row html.Td(["Market Cap"]), html.Td([marketcap], className="right-align bold") ]), html.Tr([ # Number of Shares row html.Td(["Number of Shares"]), html.Td([shares], className="right-align bold") ]), html.Tr([ # 1 year return row html.Td(["1 Year Return"]), html.Td([return_1yr], className="right-align bold") ]), html.Tr(get_pdseries_html_row(eps)), html.Tr(get_pdseries_html_row(book_value_per_share)), html.Tr(get_pdseries_html_row(free_cash_flow_per_share)), html.Tr(get_pdseries_html_row(payout_ratio)), html.Tr([ # Sector row html.Td(["Sector"]), html.Td([stock.sector], className="right-align bold") ]) ]) ], className="highlight") return table
def make_keyratios_table(self, company_name): html_content = [] num = 0 n = self.startrow market_avg = pickle.load( open(f"{PATH}/data/pickles/average_keyratios.pickle", "rb")) for val in self.values: # val returns a list of pandas series that all use the same header columns. table = [] print(val, "VAL") print(self.values[num], "V1", type(self.values[num])) print(self.values[num][self.index], "V2") print(self.values[num][self.index].index, "V3") print(self.values[num][self.index].index.tolist(), "V4") print(self.values[num][self.index].index.tolist()[n[num]]) tr = html.Thead([ html.Tr([ # horizontal header showing the dates html.Th(), html.Th( [self.values[num][self.index].index.tolist()[n[num]]], scope="col"), html.Th([ self.values[num][self.index].index.tolist()[n[num] - 1] ], scope="col"), html.Th([ self.values[num][self.index].index.tolist()[n[num] - 2] ], scope="col"), html.Th([ self.values[num][self.index].index.tolist()[n[num] - 3] ], scope="col"), html.Th([ self.values[num][self.index].index.tolist()[n[num] - 4] ], scope="col"), html.Th([ self.values[num][self.index].index.tolist()[n[num] - 5] ], scope="col"), html.Th("Market Average", scope='col') ]) ]) table.append(tr) category = self.title[num] if category == "PROFITABILITY": category = "profitability_data" elif category == "CASH FLOW": category = "cashflow_data" elif category == "LIQUIDITY": category = "liquidity_data" elif category == "EFFICIENCY": category = "efficiency_data" elif category == "REVENUE GROWTH": category = "rev_growth_data" elif category == "NET INCOME GROWTH": category = "inc_growth_data" elif category == "OPERATING INCOME GROWTH": category = "ope_growth_data" elif category == "EPS GROWTH": category = "eps_growth_data" elif category == "FINANCIAL": category = "financials_data" for v in val: # the rows print(v, type(v), "111111111111111111") print(v.name, "2222222222222") market_avg_value = market_avg[category][v.name][0] market_avg_value = round(market_avg_value, 2) title = str(v.name.title()) if "Dkk" in title: title = title.replace("Dkk", "DKK") if "Eur" in title: title = title.replace("Eur", "EUR") if "Usd" in title: title = title.replace("Usd", "USD") if "Sek" in title: title = title.replace("Sek", "SEK") if "Gbp" in title: title = title.replace("Gbp", "GBP") if "*" in title: title = title.replace(" *", "") if "Year Over Year" == title: title = title + " %" if "3-Year Average" == title: title = title + " %" if "5-Year Average" == title: title = title + " %" if "10-Year Average" == title: title = title + " %" rows_value = [ html.Th([title], scope="row", className="table-th") ] listed_values = [ str(v.get_values()[n[num]]), str(v.get_values()[n[num] - 1]), str(v.get_values()[n[num] - 2]), str(v.get_values()[n[num] - 3]), str(v.get_values()[n[num] - 4]), str(v.get_values()[n[num] - 5]), str(market_avg_value) ] for sort in listed_values: if sort == "*": value_sorted = "-" else: value_sorted = millify.prettify(sort) rows_value.append(html.Td(value_sorted)) row = html.Tbody([html.Tr(rows_value)]) table.append(row) tables = html.Div( [ html.H5(self.title[num], className="center-align myblue-text"), html.Div(className="divider"), html.Div([ # table html.Table(table, className='highlight centered') ]) ], className="col s12 pt15") html_content.append(tables) num += 1 return html_content
def format_number(value): """ Format number to be easily read by humans. """ if value > 1000000: return millify(value, precision=2) return prettify(value)
import pygame, sys, time from pygame.locals import * from millify import millify, prettify pygame.mixer.init() pygame.init() music = open("music.txt", "r+") pygame.mixer.music.load("soundtrack.wav") x = int(music.read()) WHITE = 255, 255, 255 font = pygame.font.SysFont(None, 44) cpsecond = open("clickpersecond.txt", "r+") cps = int(cpsecond.read()) baltotal = open("totalbal.txt", "r+") totalbal = int(baltotal.read()) totalbalM = prettify(totalbal, '.') clock = pygame.time.Clock() w = 800 h = 600 screen = pygame.display.set_mode((w, h)) pygame.display.set_caption('Tap Simulator') Loop = True background = pygame.image.load("Background.jpg") egg = pygame.image.load("egg.png") resized_egg = pygame.transform.scale(egg, (282, 352)) text = font.render(f'Your total clicks are {totalbalM}', True, WHITE) pygame.mixer.music.play(-1, 0.0) volume = pygame.image.load("volume.png") mute = pygame.image.load("mute.png") resized_volume = pygame.transform.scale(volume, (100, 100)) resized_mute = pygame.transform.scale(mute, (100, 100))