-
Notifications
You must be signed in to change notification settings - Fork 6
/
swan_cli_auto.py
53 lines (39 loc) · 2.11 KB
/
swan_cli_auto.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
import argparse
import os
import time
import logging
from task_sender.swan_task_sender import get_task_info,get_assigned_tasks,send_autobid_deal,update_assigned_task
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Swan client autobid')
parser.add_argument('function', metavar='task/deal', choices=['auto'], type=str, nargs="?",
help='Automatically send autobid deals')
parser.add_argument('--out-dir', dest='out_dir', help="Path to the dir to metadata csv and task csv")
parser.add_argument('--config', dest='config_path', default="./config.toml",
help="Path to the config file (default: ./config.toml)")
args = parser.parse_args()
config_path = args.__getattribute__('config_path')
config_path = os.path.abspath(config_path)
if args.__getattribute__('function') == "auto":
out_dir = args.__getattribute__('out_dir')
while True:
try:
logging.info('Autobid scan start at %s'% int(time.time()))
tasks_dict = get_assigned_tasks(config_path)
for task in tasks_dict["Assigned tasks"]:
assigned_task = get_task_info(task["uuid"],config_path)
assigned_task_info = assigned_task["task"]
if assigned_task_info:
assigned_miner_id = assigned_task_info['miner_id']
deals = assigned_task['deals']
info_output_csv_path = send_autobid_deal(deals,assigned_miner_id,assigned_task_info,config_path,out_dir)
if info_output_csv_path:
update_assigned_task(config_path, assigned_task_info['uuid'], info_output_csv_path)
else:
continue
time.sleep(30)
logging.info('Autobid scan done at %s'% int(time.time()))
time.sleep(30)
except Exception as e:
logging.info('Autobid scan failed at %s'% int(time.time()))
logging.error(e)
time.sleep(30)