43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
import logging
|
|
import asyncio
|
|
import sys
|
|
import csv
|
|
from argparse import ArgumentParser
|
|
from pathlib import Path
|
|
|
|
from . import get_all_data, log
|
|
|
|
|
|
async def main() -> None:
|
|
parser = ArgumentParser(description="Scrape all stock symbols")
|
|
parser.add_argument(
|
|
'-v', '--verbose',
|
|
action='store_true',
|
|
help="If set, prints all sorts of stuff."
|
|
)
|
|
parser.add_argument(
|
|
'-S', '--sequential',
|
|
action='store_true',
|
|
help="If set, all requests are performed sequentially; otherwise async capabilities are used for concurrency."
|
|
)
|
|
parser.add_argument(
|
|
'-f', '--to-file',
|
|
type=Path,
|
|
help="Writes results to the specified destination file. If omitted results are printed to stdout."
|
|
)
|
|
args = parser.parse_args()
|
|
if args.verbose:
|
|
log.setLevel(logging.DEBUG)
|
|
|
|
data = await get_all_data(args.sequential)
|
|
|
|
if args.to_file is None:
|
|
csv.writer(sys.stdout).writerows(data)
|
|
else:
|
|
with open(args.to_file, 'w') as f:
|
|
csv.writer(f).writerows(data)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|