def _get_ranks(self, query, temp):
"""Internal function for get gainers and losers
Args:
query: Query to obtain ranks, gainers or losers
temp: Temporal period obtaining gainers or losers,
1h, 24h or 7d
"""
url = urljoin(self.urls["web"], 'gainers-losers/')
html = self._html(url)
call = str(query) + '-' + str(temp)
response = []
html_rank = html.find('div', {'id': call}).find_all('tr')
for curr in html_rank[1:]:
_childs, childs = (curr.contents, [])
for c in _childs:
if c != '\n':
childs.append(c)
for n, g in enumerate(childs):
if n == 1:
name = str(g.a.getText())
elif n == 2:
symbol = str(g.string)
elif n == 3:
_volume_24h = sub(r'\$|,', '', g.a.getText())
volume_24h = self.parse_int(_volume_24h)
elif n == 4:
_price = sub(r'\$|,', '', g.a.getText())
price = self.parse_float(_price)
elif n == 5:
percent = self.parse_float(sub(r'%', '', g.string))
currency = {'symbol': symbol, 'name': name,
'24h_volume_usd': volume_24h,
'price_usd': price, 'percent_change': percent}
response.append(currency)
return response
评论列表
文章目录