use file with links as arguments

This commit is contained in:
Maks Snegov
2014-07-20 13:48:18 +04:00
parent 514b39d287
commit 5c9d04cf3d

View File

@@ -126,19 +126,13 @@ def complete_url(url, base_url):
return url return url
def main(): def process_url(url):
parser = argparse.ArgumentParser( print('Processing URL: %s' % url)
description='Nevernote - download pages locally.')
parser.add_argument('urls', metavar='URL', type=str, nargs='+',
help='URL of page to download')
args = parser.parse_args()
for url in args.urls:
try: try:
url_duplicate(url) url_duplicate(url)
except UrlDuplicateError as e: except UrlDuplicateError as e:
print(e) print(e)
continue return
page = get_text(url) page = get_text(url)
parser = TitleParser(strict=False) parser = TitleParser(strict=False)
parser.feed(page) parser.feed(page)
@@ -148,5 +142,21 @@ def main():
write_file(page, parser.title, comment=url) write_file(page, parser.title, comment=url)
def main():
parser = argparse.ArgumentParser(
description='Nevernote - download pages locally.')
parser.add_argument('urls', metavar='URL', type=str, nargs='+',
help='URL of page to download')
args = parser.parse_args()
for arg in args.urls:
if os.path.isfile(arg):
print('Found file %s' % arg)
for url in (line.strip() for line in open(arg)):
process_url(url)
else:
process_url(arg)
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())