Skip to content

Commit

Permalink
Fix #31
Browse files Browse the repository at this point in the history
  • Loading branch information
marzzzello committed Oct 29, 2023
1 parent 3f98e17 commit 4d6a4a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pytr/dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@


class DL:
def __init__(self, tr, output_path, filename_fmt, since_timestamp=0, history_file='pytr_history', max_workers=8):
def __init__(
self,
tr,
output_path,
filename_fmt,
since_timestamp=0,
history_file='pytr_history',
max_workers=8,
universal_filepath=False,
):
'''
tr: api object
output_path: name of the directory where the downloaded files are saved
Expand All @@ -24,6 +33,7 @@ def __init__(self, tr, output_path, filename_fmt, since_timestamp=0, history_fil
self.history_file = self.output_path / history_file
self.filename_fmt = filename_fmt
self.since_timestamp = since_timestamp
self.universal_filepath = universal_filepath

requests_session = session()
if self.tr._weblogin:
Expand Down Expand Up @@ -117,8 +127,12 @@ def dl_doc(self, doc, titleText, subtitleText, subfolder=None):
filepath = directory / doc_type / f'{filename}.pdf'
filepath_with_doc_id = directory / doc_type / f'{filename_with_doc_id}.pdf'

filepath = sanitize_filepath(filepath, '_', 'auto')
filepath_with_doc_id = sanitize_filepath(filepath_with_doc_id, '_', 'auto')
if self.universal_filepath:
filepath = sanitize_filepath(filepath, '_', 'universal')
filepath_with_doc_id = sanitize_filepath(filepath_with_doc_id, '_', 'universal')
else:
filepath = sanitize_filepath(filepath, '_', 'auto')
filepath_with_doc_id = sanitize_filepath(filepath_with_doc_id, '_', 'auto')

if filepath in self.filepaths:
self.log.debug(f'File {filepath} already in queue. Append document id {doc_id}...')
Expand Down
2 changes: 2 additions & 0 deletions pytr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def formatter(prog):
parser_dl_docs.add_argument(
'--workers', help='Number of workers for parallel downloading', metavar='WORKERS', default=8, type=int
)
parser_dl_docs.add_argument('--universal', help='Platform independent file names', action='store_true')
# portfolio
info = 'Show current portfolio'
parser_cmd.add_parser(
Expand Down Expand Up @@ -202,6 +203,7 @@ def main():
args.format,
since_timestamp=since_timestamp,
max_workers=args.workers,
universal_filepath=args.universal,
)
asyncio.get_event_loop().run_until_complete(dl.dl_loop())
elif args.command == 'set_price_alarms':
Expand Down

0 comments on commit 4d6a4a9

Please sign in to comment.