Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions docdl/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""download documents from web portals"""

import os
import pkg_resources
import click
import click_plugins
Expand Down Expand Up @@ -85,6 +86,16 @@
help="webdriver to use for selenium based plugins",
show_default=True
)
@click.option(
"-T",
"--time-preserve",
type=bool,
default=True,
envvar="DOCDL_TIME_PRESERVE",
show_envvar=True,
help="preserve the document creation time for the downloaded file",
show_default=True
)
@click.option(
"-t",
"--timeout",
Expand Down Expand Up @@ -131,7 +142,7 @@
# pylint: disable=W0613,C0103,R0913
def documentdl(
ctx, username, password, string_matches, regex_matches, jq_matches,
headless, browser, timeout, image_loading, action, output_format
headless, browser, time_preserve, timeout, image_loading, action, output_format
):
"""download documents from web portals"""
# set browser that SeleniumWebPortal plugins should use
Expand Down Expand Up @@ -179,7 +190,10 @@ def run(ctx, plugin_class):
continue
# download ?
if root_params['action'] == "download":
portal.download(document)
filename = portal.download(document)
if root_params['time_preserve']:
timest = document.attributes['date'].timestamp()
os.utime(filename, (timest, timest))
# line buffered dict output?
if root_params['output_format'] == "dicts":
# always output as json dict
Expand Down