forked from bitphage/golos-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_conversion_requests.py
executable file
·81 lines (64 loc) · 2.51 KB
/
get_conversion_requests.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
79
80
81
#!/usr/bin/env python
import sys
import json
import argparse
import logging
import yaml
from golos import Steem
from golos.account import Account
from pprint import pprint
from datetime import timedelta
from datetime import datetime
import functions
log = logging.getLogger('functions')
def main():
parser = argparse.ArgumentParser(
description='Find all GBG conversion requests',
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('-n', '--notify', action='store_true',
help='send message to accounts who uses conversions')
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)
golos = Steem(nodes=conf['nodes_old'], keys=conf['keys'])
c = golos.get_account_count()
log.debug('total accounts: {}'.format(c))
accs = golos.get_all_usernames()
# obtain median and market prices whether we're going to send a notification
if args.notify:
bid = functions.get_market_price(golos)
median = functions.get_median_price(golos)
if not bid or not median:
log.critical('failed to obtain price')
sys.exit(1)
start = datetime.utcnow()
for acc in accs:
r = golos.get_conversion_requests(acc)
if r:
d = datetime.strptime(r[0]['conversion_date'], '%Y-%m-%dT%H:%M:%S')
print('{:<16} {:<18} {:>7}'.format(
r[0]['owner'],
r[0]['amount'],
d.strftime('%Y-%m-%d %H:%M')
))
if args.notify:
msg = conf['notify_message'].format(median, bid)
functions.transfer(golos, conf['notify_account'], acc, '0.001', 'GBG', msg)
log.debug('getting conversion requests took {:.2f} seconds'.format(
(datetime.utcnow() - start).total_seconds()))
if __name__ == '__main__':
main()