diff options
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 22 |
1 files changed, 13 insertions, 9 deletions
@@ -62,7 +62,7 @@ def make_order(market, value, currency, action="acquire", | |||
62 | 62 | ||
63 | def get_user_market(config_path, user_id, debug=False): | 63 | def get_user_market(config_path, user_id, debug=False): |
64 | pg_config, report_path = parse_config(config_path) | 64 | pg_config, report_path = parse_config(config_path) |
65 | market_config = list(fetch_markets(pg_config, str(user_id)))[0][0] | 65 | market_config = list(fetch_markets(pg_config, str(user_id)))[0][1] |
66 | args = type('Args', (object,), { "debug": debug, "quiet": False })() | 66 | args = type('Args', (object,), { "debug": debug, "quiet": False })() |
67 | return market.Market.from_config(market_config, args, user_id=user_id, report_path=report_path) | 67 | return market.Market.from_config(market_config, args, user_id=user_id, report_path=report_path) |
68 | 68 | ||
@@ -71,9 +71,9 @@ def fetch_markets(pg_config, user): | |||
71 | cursor = connection.cursor() | 71 | cursor = connection.cursor() |
72 | 72 | ||
73 | if user is None: | 73 | if user is None: |
74 | cursor.execute("SELECT config,user_id FROM market_configs") | 74 | cursor.execute("SELECT id,config,user_id FROM market_configs") |
75 | else: | 75 | else: |
76 | cursor.execute("SELECT config,user_id FROM market_configs WHERE user_id = %s", user) | 76 | cursor.execute("SELECT id,config,user_id FROM market_configs WHERE user_id = %s", user) |
77 | 77 | ||
78 | for row in cursor: | 78 | for row in cursor: |
79 | yield row | 79 | yield row |
@@ -132,10 +132,12 @@ def parse_args(argv): | |||
132 | 132 | ||
133 | return args | 133 | return args |
134 | 134 | ||
135 | def process(market_config, user_id, report_path, args): | 135 | def process(market_id, market_config, user_id, report_path, args, pg_config): |
136 | try: | 136 | try: |
137 | market.Market\ | 137 | market.Market\ |
138 | .from_config(market_config, args, user_id=user_id, report_path=report_path)\ | 138 | .from_config(market_config, args, |
139 | pg_config=pg_config, market_id=market_id, | ||
140 | user_id=user_id, report_path=report_path)\ | ||
139 | .process(args.action, before=args.before, after=args.after) | 141 | .process(args.action, before=args.before, after=args.after) |
140 | except Exception as e: | 142 | except Exception as e: |
141 | print("{}: {}".format(e.__class__.__name__, e)) | 143 | print("{}: {}".format(e.__class__.__name__, e)) |
@@ -149,11 +151,13 @@ def main(argv): | |||
149 | import threading | 151 | import threading |
150 | market.Portfolio.start_worker() | 152 | market.Portfolio.start_worker() |
151 | 153 | ||
152 | for market_config, user_id in fetch_markets(pg_config, args.user): | 154 | for row in fetch_markets(pg_config, args.user): |
153 | threading.Thread(target=process, args=[market_config, user_id, report_path, args]).start() | 155 | threading.Thread(target=process, args=[ |
156 | *row, report_path, args, pg_config | ||
157 | ]).start() | ||
154 | else: | 158 | else: |
155 | for market_config, user_id in fetch_markets(pg_config, args.user): | 159 | for row in fetch_markets(pg_config, args.user): |
156 | process(market_config, user_id, report_path, args) | 160 | process(*row, report_path, args, pg_config) |
157 | 161 | ||
158 | if __name__ == '__main__': # pragma: no cover | 162 | if __name__ == '__main__': # pragma: no cover |
159 | main(sys.argv[1:]) | 163 | main(sys.argv[1:]) |