__copyright__ = "Copyright (C) 2024 PhiloSoft Design"
__license__ = "GNU GPL"
+import argparse
import sys
from bkmk_objects import Bookmark
def run():
print("Broytman get_url, Copyright (C) 2024 PhiloSoft Design")
- if len(sys.argv) != 3:
- sys.stderr.write("Usage: get_url.py URL output_file\n")
- sys.exit(1)
+ parser = argparse.ArgumentParser(description='Get URL')
+ parser.add_argument('-H', '--headers', help='file name to save headers')
+ parser.add_argument('-B', '--body', help='file name to save body')
+ parser.add_argument('URL', help='URL')
+ args = parser.parse_args()
from robots import robot
print("Using", robot)
robot = robot(sys.stdout.write)
- url = sys.argv[1]
- output_fname = sys.argv[2]
-
+ url = args.URL
bookmark = Bookmark(href=url, add_date=None)
bookmark.parent = None
robot.smart_get(bookmark, url, True)
if error:
- print(error)
+ sys.stderr.write(error + '\n')
elif redirect_code:
print("Moved to: %s" % redirect_to)
else:
- print(headers)
- with open(output_fname, 'wb') as outfile:
- outfile.write(content)
+ if args.headers:
+ with open(args.headers, 'wb') as outfile:
+ outfile.write(str(headers).encode())
+ else:
+ print(headers)
+
+ if args.body:
+ with open(args.body, 'wb') as outfile:
+ outfile.write(content)
+ else:
+ print(content)
robot.stop()