From 29c82a4ff70e5985f1322e20a087a84484508fd6 Mon Sep 17 00:00:00 2001 From: Daniil Fajnberg Date: Fri, 12 Nov 2021 16:30:51 +0100 Subject: [PATCH] renamed modules and package (removed dashes) --- setup.cfg | 6 +-- src/stocksymbolscraper/__init__.py | 0 src/stocksymbolscraper/__main__.py | 42 +++++++++++++++++++ .../main.py => stocksymbolscraper/scrape.py} | 38 ----------------- 4 files changed, 45 insertions(+), 41 deletions(-) create mode 100644 src/stocksymbolscraper/__init__.py create mode 100644 src/stocksymbolscraper/__main__.py rename src/{stock-symbol-scraper/main.py => stocksymbolscraper/scrape.py} (84%) diff --git a/setup.cfg b/setup.cfg index bd0f0e7..d3e8f25 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,14 +1,14 @@ [metadata] -name = stock-symbol-scraper +name = stocksymbolscraper version = 0.0.1 author = Daniil & Maximilian F. author_email = mail@placeholder123.to description = Scraper for stock symbols long_description = file: README.md long_description_content_type = text/markdown -url = https://git.fajnberg.de/daniil/stock-symbol-scraper +url = https://git.fajnberg.de/daniil/stocksymbolscraper project_urls = - Bug Tracker = https://github.com/daniil-berg/stock-symbol-scraper/issues + Bug Tracker = https://github.com/daniil-berg/stocksymbolscraper/issues classifiers = Programming Language :: Python :: 3 License :: OSI Approved :: MIT License diff --git a/src/stocksymbolscraper/__init__.py b/src/stocksymbolscraper/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/stocksymbolscraper/__main__.py b/src/stocksymbolscraper/__main__.py new file mode 100644 index 0000000..bdfa942 --- /dev/null +++ b/src/stocksymbolscraper/__main__.py @@ -0,0 +1,42 @@ +import logging +import asyncio +import sys +import csv +from argparse import ArgumentParser +from pathlib import Path + +from .scrape import get_all_data, log + + +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 = asyncio.run(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__': + main() diff --git a/src/stock-symbol-scraper/main.py b/src/stocksymbolscraper/scrape.py similarity index 84% rename from src/stock-symbol-scraper/main.py rename to src/stocksymbolscraper/scrape.py index 0f987a6..5421f53 100644 --- a/src/stock-symbol-scraper/main.py +++ b/src/stocksymbolscraper/scrape.py @@ -1,10 +1,6 @@ import logging import re -import csv -import sys import asyncio -from argparse import ArgumentParser -from pathlib import Path from datetime import datetime from string import ascii_uppercase from math import inf @@ -182,37 +178,3 @@ async def get_all_data(sequential: bool = False) -> list[row_type]: for result in results: data.extend(result) return data - - -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 = asyncio.run(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__': - main()