forked from bitphage/golos-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_rewards.py
executable file
·78 lines (60 loc) · 2.48 KB
/
find_rewards.py
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
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
import sys
import json
import argparse
import logging
import yaml
from datetime import datetime
from pprint import pprint
from golos import Steem
from golos.account import Account
from golos.amount import Amount
from golos.converter import Converter
import functions
log = logging.getLogger('functions')
def main():
parser = argparse.ArgumentParser(
description='Scan account history looking for author or curator payouts',
epilog='Report bugs to: https://github.com/bitfag/golos-scripts/issues')
parser.add_argument('-d', '--debug', action='store_true',
help='enable debug output'),
parser.add_argument('-c', '--config', default='./common.yml',
help='specify custom path for config file')
parser.add_argument('-t', '--type', default='author', choices=['author', 'curator'],
help='reward type, "author" or "curator", default: author')
parser.add_argument('account',
help='account to scan')
args = parser.parse_args()
# create logger
if args.debug == True:
log.setLevel(logging.DEBUG)
else:
log.setLevel(logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter("%(asctime)s %(levelname)s: %(message)s")
handler.setFormatter(formatter)
log.addHandler(handler)
# parse config
with open(args.config, 'r') as ymlfile:
conf = yaml.load(ymlfile)
if args.type == 'author':
ops = ['author_reward']
elif args.type == 'curator':
ops = ['curation_reward']
golos = Steem(nodes=conf['nodes_old'], keys=conf['keys'])
cv = Converter(golos)
account = Account(args.account, steemd_instance=golos)
history = account.rawhistory(only_ops=ops)
for item in history:
#pprint(item)
permlink = item[1]['op'][1]['permlink']
payout_timestamp = datetime.strptime(item[1]['timestamp'], '%Y-%m-%dT%H:%M:%S')
sbd_payout = Amount(item[1]['op'][1]['sbd_payout'])
steem_payout = Amount(item[1]['op'][1]['steem_payout'])
vesting_payout = Amount(item[1]['op'][1]['vesting_payout'])
gp = cv.vests_to_sp(vesting_payout.amount)
golos_payout = steem_payout.amount + gp
gpg_repr = sbd_payout.amount + functions.convert_golos_to_gbg(golos, golos_payout, price_source='market')
print('{} {}: {} {} {:.3f} GP, GBG repr: {:.3f}'.format(payout_timestamp, permlink, sbd_payout, steem_payout, gp, gpg_repr))
if __name__ == '__main__':
main()