|
1 |
| -""" |
2 |
| -Module that contains the command line app. |
3 |
| -
|
4 |
| -Why does this file exist, and why not put this in __main__? |
5 |
| -
|
6 |
| - You might be tempted to import things from __main__ later, but that will cause |
7 |
| - problems: the code will get executed twice: |
| 1 | +import argparse |
8 | 2 |
|
9 |
| - - When you run `python -memtl` python will execute |
10 |
| - ``__main__.py`` as a script. That means there will not be any |
11 |
| - ``emtl.__main__`` in ``sys.modules``. |
12 |
| - - When you import __main__ it will get executed again (as a module) because |
13 |
| - there"s no ``emtl.__main__`` in ``sys.modules``. |
| 3 | +from .core import login |
| 4 | +from .utils import get_logger |
14 | 5 |
|
15 |
| - Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration |
16 |
| -""" |
| 6 | +logger = get_logger(__name__) |
17 | 7 |
|
18 |
| -import argparse |
19 |
| - |
20 |
| -from .core import emt |
21 | 8 |
|
| 9 | +logger.info("cli") |
22 | 10 | parser = argparse.ArgumentParser(prog="emt", description="东方财富交易接口", epilog="东方财富交易接口")
|
23 |
| -parser.add_argument("-u", "--user", required=True) |
24 |
| -parser.add_argument("-p", "--password", required=True) |
| 11 | +parser.add_argument("-u", "--user", required=False) |
| 12 | +parser.add_argument("-p", "--password", required=False) |
| 13 | +group = parser.add_mutually_exclusive_group() |
| 14 | +group.add_argument("-b", "--buy", help="买入股票,格式为:代码-价格-数量。例子买入一手平安银行:000001-10.21-100") |
| 15 | +group.add_argument("-s", "--sell", help="卖出股票,格式为:代码-价格-数量。卖一手平安银行:000001-10.21-100") |
| 16 | +group.add_argument("-q", "--query", type=str, choices=["asset", "order", "trade"], help="查询账户的资产、挂单、成交") |
25 | 17 |
|
26 | 18 |
|
27 | 19 | def run(args=None):
|
| 20 | + logger.info(args) |
28 | 21 | args = parser.parse_args(args=args)
|
29 |
| - print(emt(args.user, args.password)) |
| 22 | + logger.info(args) |
| 23 | + login(args.user, args.password) |
30 | 24 | parser.exit(0)
|
| 25 | + |
| 26 | + |
| 27 | +if __name__ == "__main__": |
| 28 | + run() |
0 commit comments