Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def getUserArtistsPrev(self):
user_top_artists = self.__client.current_user_followed_artists(
limit=50
)
artists = []
for artist in user_top_artists['artists']['items']:
followers = humanize.intword(artist['followers']['total'])
followers_comma = humanize.intcomma(artist['followers']['total'])
if str(followers).isdigit():
followers = followers_comma
try:
data = {
'spotify':artist['external_urls']['spotify'],
'uri':artist['uri'],
'id':artist['id'],
'name':artist['name'],
'image':artist['images'][0]['url'],
'popularity':artist['popularity'],
'followers':artist['followers']['total'],
tabulated_data = []
tabulated_data.append(copy.copy(fields)) # Headers in position 0
pos = 0
for header in tabulated_data[0]: # Headers in position 0
good_header = difflib.get_close_matches(header, fields_good_name.keys())[0]
tabulated_data[0][pos] = fields_good_name[good_header]
if good_header in ['price', 'market_cap']:
tabulated_data[0][pos] = tabulated_data[0][pos].replace('USD', currency)
pos += 1
for item in data:
tab_item = []
for field in fields:
if humanize and re.search('market_cap*', field):
tab_item.append(intword(int(float(item[field]))))
else:
tab_item.append(item[field])
tabulated_data.append(copy.copy(tab_item))
return tabulated_data
def edges(
graph: BELGraph,
*,
examples: bool = True,
minimum: Optional[int] = None,
file: Optional[TextIO] = None,
) -> None:
"""Print a summary of the edges in the graph."""
df = edge_table_df(graph, examples=examples, minimum=minimum)
headers = list(df.columns)
headers[0] += ' ({})'.format(intword(len(df.index)))
print(tabulate(df.values, headers=headers), file=file)
def humanize_int(i):
"""Format numbers for easier readability. Numbers over 1 million are comma formatted, numbers
over 1 million will be formatted like "1.2 million"
Args:
i: int to format.
Returns:
string of formatted number.
"""
if i < 1000000:
return humanize.intcomma(i)
return humanize.intword(i)
def format_isk_human(value):
if value is None:
return ""
try:
return "%s ISK" % humanize.intword(value, format='%.2f')
except:
return str(value)
# SOURCE: https://github.com/jmoiron/humanize
# pip install humanize
import humanize
# Integer humanization:
print(humanize.intcomma(12345)) # '12,345'
print(humanize.intcomma(123456789)) # '123,456,789'
print()
print(humanize.intword(123455913)) # '123.5 million'
print(humanize.intword(12345591313)) # '12.3 billion'
print(humanize.intword(1339014900000)) # '1.3 trillion'
print()
print(humanize.apnumber(4)) # 'four'
print(humanize.apnumber(7)) # 'seven'
print(humanize.apnumber(41)) # '41'
def human_number(num):
n = humanize.intword(int(math.ceil(num))).lower()
if re.search(r"^(\d+)\.0 ([A-Za-z]+)$", n):
m = re.search(r"^(\d+)\.0 ([A-Za-z]+)$", n)
n = m.group(1) + " " + m.group(2)
return n
def intword(context, value):
return humanize.intword()