From 68a0e30b3f4ca57f27c0ddd24429b702ecd94bde Mon Sep 17 00:00:00 2001 From: Christopher Teutsch Date: Fri, 3 May 2019 23:40:14 +0200 Subject: [PATCH] Proper prompts --- crawl.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/crawl.py b/crawl.py index 18a9877..ecd9cae 100755 --- a/crawl.py +++ b/crawl.py @@ -49,6 +49,11 @@ parser.add_argument( action='store_true', help='Reverse direction (EUR -> currency)' ) +parser.add_argument( + '--cache-dir', + dest='cache_dir', + help='Override the default cache directory with your own path' +) exc_group = parser.add_mutually_exclusive_group() exc_group.add_argument( '-i', '--interactive', @@ -111,7 +116,7 @@ def is_float(string: str) -> bool: return False def _retrieve_file(date: DTDate, card_type: List[str] = CARD_VISA) -> BinaryIO: # pylint: disable=dangerous-default-value - print('Downloading newest rates...') + print('Downloading newest rates...', end='') b = m.Browser() # Firefox 64 User-Agent # ua = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0' @@ -135,7 +140,7 @@ def _retrieve_file(date: DTDate, card_type: List[str] = CARD_VISA) -> BinaryIO: rq = fm_i.click(name='submitButton', coord=(random.randint(1, 119), random.randint(1, 20))) rq.add_header('Accept', '*/*') rp = b.retrieve(rq) - print('Done.') + print(' Done.') return open(rp[0], 'rb') def _get_date() -> DTDate: @@ -190,7 +195,10 @@ if args.date: else: retrieve_date = _get_date() -filepath = pathlib.Path(appdirs.user_cache_dir('FirstDataCrawler', 'iwonder')) +if args.cache_dir is not None: + filepath = pathlib.Path(os.path.abspath(args.cache_dir)) +else: + filepath = pathlib.Path(appdirs.user_cache_dir('FirstDataCrawler', 'iwonder')) if not filepath.exists(): filepath.mkdir(parents=True) filename = filepath / (retrieve_date.strftime('%Y%m%d') + '.pdf') @@ -209,7 +217,6 @@ else: if args.interactive: try: - print('Ready.') while True: _process_stdin(input('> '), results) except (KeyboardInterrupt, EOFError):