2020-10-12 14:11:55 +02:00
|
|
|
#!/usr/bin/env python
|
2020-10-13 21:13:49 +02:00
|
|
|
from url2markdown.cli import cli
|
|
|
|
from url2markdown.downloader import downloader
|
|
|
|
from url2markdown.file import write_to_file
|
|
|
|
from url2markdown.header import Header
|
2020-10-12 22:26:21 +02:00
|
|
|
|
2020-10-12 14:11:55 +02:00
|
|
|
|
2020-10-13 22:47:11 +02:00
|
|
|
def main(url, topics):
|
|
|
|
article = downloader(url)
|
|
|
|
header = Header(article, topics)
|
2020-10-12 22:26:21 +02:00
|
|
|
write_to_file(article, header.build_header())
|
2020-10-12 14:11:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-10-13 22:47:11 +02:00
|
|
|
args = cli()
|
|
|
|
if args.url:
|
|
|
|
main(args.url, args.topics)
|
|
|
|
if args.file:
|
|
|
|
with args.file as input_file:
|
|
|
|
for line in input_file:
|
|
|
|
try:
|
2020-10-13 22:54:06 +02:00
|
|
|
stripped_line = line.strip()
|
|
|
|
url, topics = stripped_line.split(' ')
|
2020-10-13 22:47:11 +02:00
|
|
|
except ValueError:
|
|
|
|
url = line
|
|
|
|
topics = []
|
2020-11-09 12:31:48 +01:00
|
|
|
if url != '\n':
|
|
|
|
main(url, topics)
|