-
-
Save Kefkius/74aa3d9977e856ef7c472923e53d8816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from lxml import html | |
import requests | |
import re | |
import sys | |
class CoinMarketCap(object): | |
def __init__(self, currency): | |
self.tree = html.fromstring(requests.get('http://coinmarketcap.com').text) | |
data = self.tree.xpath('//div[@id="currency-exchange-rates"]/@data-{}'.format(currency)) | |
if not data: | |
raise Exception('Unknown currency: "{}"'.format(currency)) | |
self.fiat = float(data[0]) | |
def get_price(self, coin_name): | |
rate = float(self.tree.xpath('//tr[@id="id-%s"]/td[4]/a[@class="price"]/text()'%coin_name.strip().lower())[0].split(' ')[1]) | |
return rate/self.fiat | |
class Steem(object): | |
def __init__(self, user_name, ratio_steem_fiat, ratio_fiat_dollar): | |
assert(user_name) | |
self.steemd_url = 'https://steemd.com/@{}'.format(user_name) | |
self.steemd_page = requests.get(self.steemd_url).text | |
self.steem_per_mvests = float(re.search("steem_per_mvests</samp></th></tr><tr><td><i>([0-9]*\.?[0-9]*)</i>", requests.get('https://steemd.com/').text).group(1)) | |
self.ratio_steem_fiat = ratio_steem_fiat | |
self.ratio_fiat_dollar = ratio_fiat_dollar | |
def print_balance(self, currency): | |
steem_vests = float(re.search(r'<th>Vesting shares</th><td>([0-9]*\,?[0-9]*i*\.?[0-9]*)<m>', self.steemd_page).group(1).replace(',','')) | |
steems = float(re.search(r'<th>Balance</th><td>([0-9]*\.?[0-9]*) STEEM</td>', self.steemd_page).group(1)) | |
steem_dollars = float(re.search(r'\$([0-9]*\.?[0-9]*)', self.steemd_page).group(1)) | |
steem_vests_in_euros = steem_vests*self.steem_per_mvests*self.ratio_steem_fiat | |
steems_in_euros = steems*self.ratio_steem_fiat | |
steem_dollars_in_euros = steem_dollars/self.ratio_fiat_dollar | |
print('Steem balance') | |
print('\tSteem vests: \t{0:.2f}M \t({1:.2f} {2})'.format(steem_vests, steem_vests_in_euros, currency)) | |
print('\tSteem: \t\t{0:.3f} \t({1:.2f} {2})'.format(steems, steems_in_euros, currency)) | |
print('\tSteem Dollars: \t{0:.3f} \t({1:.2f} {2})'.format(steem_dollars, steem_dollars_in_euros, currency)) | |
print('Total: \t\t\t\t{0:.2f} {1}'.format(steem_vests_in_euros+steems_in_euros+steem_dollars_in_euros, currency)) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--username', '-u', type=str, default='oscarp', help='Account name') | |
parser.add_argument('--currency', '-c', type=str, default='eur', help='Fiat currency') | |
args = parser.parse_args() | |
coinm = CoinMarketCap(args.currency) | |
ratio_euro_dollar = coinm.fiat | |
ratio_steem_fiat = coinm.get_price('STEEM') | |
Steem(args.username, ratio_steem_fiat, ratio_euro_dollar).print_balance(args.currency) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment