-
Notifications
You must be signed in to change notification settings - Fork 19
/
cli.py
executable file
·112 lines (94 loc) · 3.18 KB
/
cli.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
import argparse
import logging
from typing import Union
from src.commands.pathfinder import execute_pathfinding
from src.commands.sync import execute_sync
from src.commons import (
init_logger,
LEAGUE_NAMES,
load_excluded_traders,
)
from src.config.user_config import UserConfig
from src.core.backends.poeofficial import PoeOfficial
from src.trading.items import ItemList
parser = argparse.ArgumentParser(description="CLI interface for PathFinder")
parser.add_argument("command",
default="pathfinding",
choices=["pathfinding", "sync"],
type=str,
nargs="?",
help="Specifies what subcommand to run:\n\n\
1. pathfinding: Find profitable conversion paths (default).\n\
2. sync: Sync your public stashes into your config file."),
parser.add_argument(
"--league",
default=LEAGUE_NAMES[0],
type=str,
help="""
League specifier, ie. 'Synthesis', 'Hardcore Synthesis' or 'Flashback Event (BRE001)'.
Defaults to '{}'.""".format(LEAGUE_NAMES[0]),
)
parser.add_argument(
"--currency",
default="all",
type=str,
help=
"""Full name of currency to flip, ie. 'Cartographer's Chisel, or 'Chaos Orb'.
Defaults to all currencies.""",
)
parser.add_argument(
"--limit",
default=5,
type=int,
help="Limit the number of displayed conversions. Defaults to 5.",
)
parser.add_argument(
"--fullbulk",
default=False,
action="store_true",
help="Use all supported bulk items",
)
parser.add_argument("--nofilter",
default=False,
action="store_true",
help="Disable item pair filters")
parser.add_argument("--debug",
action="store_true",
help="Enables debug logging")
parser.add_argument("--config",
default=None,
type=str,
help="Specify your config file path")
arguments = parser.parse_args()
init_logger(arguments.debug)
# global arguments
command: str = arguments.command
league: str = arguments.league
config_file_path: Union[str, None] = arguments.config
if command == "pathfinding":
# arguments related to pathfinding
currency: Union[str, None] = arguments.currency
limit: Union[int, None] = arguments.limit
fullbulk: bool = arguments.fullbulk
no_filter: bool = arguments.nofilter
config = {"fullbulk": fullbulk}
try:
# Load user config
user_config = UserConfig.from_file(config_file_path, True)
except Exception as ex:
logging.error(f"Error: {ex.args[0]}")
exit(1)
# Load excluded trader list
excluded_traders = load_excluded_traders()
# Load item pairs
item_list = ItemList.load_from_file()
backend = PoeOfficial(item_list)
item_pairs = item_list.get_item_list_for_backend(
backend, config) if no_filter else user_config.get_item_pairs()
execute_pathfinding(currency, league, limit, item_pairs, user_config,
excluded_traders)
elif command == "sync":
execute_sync(config_file_path, league)
else:
raise Exception("Command {} does not exist".format(command))