mirror of
https://github.com/jo1gi/grawlix.git
synced 2025-12-16 04:09:10 +00:00
Add file argument to read urls from file
This commit is contained in:
parent
0d7fdd04a0
commit
03e67a6515
@ -29,6 +29,22 @@ def get_login(source: Source, config: Config, options) -> Tuple[str, str]:
|
||||
return username, password
|
||||
|
||||
|
||||
def get_urls(options) -> list[str]:
|
||||
"""
|
||||
Retrieves all available urls from input arguments
|
||||
- From urls argument
|
||||
- From file argument
|
||||
"""
|
||||
urls = []
|
||||
if options.urls:
|
||||
urls.extend(options.urls)
|
||||
if options.file:
|
||||
with open(options.file, "r") as f:
|
||||
content = f.read()
|
||||
urls.extend(content.split("\n"))
|
||||
return urls
|
||||
|
||||
|
||||
def authenticate(source: Source, config: Config, options):
|
||||
"""
|
||||
Authenticate with source
|
||||
@ -47,7 +63,8 @@ def authenticate(source: Source, config: Config, options):
|
||||
def main() -> None:
|
||||
args = arguments.parse_arguments()
|
||||
config = load_config()
|
||||
for url in args.urls:
|
||||
urls = get_urls(args)
|
||||
for url in urls:
|
||||
source: Source = find_source(url)
|
||||
if source.requires_authentication:
|
||||
authenticate(source, config, args)
|
||||
|
||||
@ -20,6 +20,12 @@ def parse_arguments():
|
||||
help = "Links to ebooks",
|
||||
nargs = "*"
|
||||
)
|
||||
parser.add_argument(
|
||||
'-f',
|
||||
'--file',
|
||||
help = "File with links (One link per line)",
|
||||
dest = "file"
|
||||
)
|
||||
# Authentication
|
||||
parser.add_argument(
|
||||
'-u',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user