This repository was archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.py
More file actions
68 lines (52 loc) · 2.28 KB
/
shared.py
File metadata and controls
68 lines (52 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from configparser import ConfigParser
from datetime import datetime
from cryptocompare import get_price
import flexpoolapi
def config():
config = ConfigParser()
config.read('config.ini')
return config
def save_config(option, value):
config = ConfigParser()
config.read('config.ini')
config['bot'][option] = value
with open('config.ini', 'w') as config_file:
config.write(config_file)
def revenue(earnings, price, worker='Total'):
return f"\n`{earnings:.6f}` ETH ~ `{earnings * price:>7.2f}` {config()['bot']['currency']} > {worker}"
def share(name, percentage):
return f'{name} (`{percentage:.1f}`%)'
def get_earnings(total_eth):
cfg = config()['bot']
miner = flexpoolapi.miner('ETH', cfg['eth_address'])
eth_price = get_price('ETH', currency=cfg['currency'])['ETH'][cfg['currency']]
total_valid_shares = miner.stats().valid_shares
reply = ''
for worker in miner.workers():
shares_percentage = worker.valid_shares / total_valid_shares * 100
earnings = shares_percentage / 100 * total_eth
reply += revenue(earnings, eth_price, share(worker.name, shares_percentage))
return reply + revenue(total_eth, eth_price)
def get_summary(earnings, start_date='', end_date=''):
cfg = config()['bot']
eth_price = get_price('ETH', currency=cfg['currency'])['ETH'][cfg['currency']]
start_date = datetime.strptime(start_date, '%Y-%m-%d')
reply = f"Address: `{cfg['eth_address']}`\n"
reply += f"\n**{start_date.strftime('%d %B %Y')}**"
days_difference = 0
if end_date:
end_date = datetime.strptime(end_date, '%Y-%m-%d')
reply += f"** - {end_date.strftime('%d %B %Y')}**"
days_difference = (end_date - start_date).days + 1
for worker in earnings['workers']:
earnings_percentage = earnings['workers'][worker] / earnings['total'] * 100
reply += revenue(earnings['workers'][worker], eth_price, share(worker, earnings_percentage))
reply += revenue(earnings['total'], eth_price)
if days_difference > 1:
average_earnings = { 'workers': {}, 'total': earnings['total'] / days_difference }
reply += '\n\n**Average per Day**'
for worker in earnings['workers']:
average_earnings['workers'][worker] = earnings['workers'][worker] / days_difference
reply += revenue(average_earnings['workers'][worker], eth_price, worker)
reply += revenue(average_earnings['total'], eth_price)
return reply