I have tried to correct the following error which basically is about the arguments for \'username\' and \'directory\'. I have tried all possible ways but no luck. Python does no
That's not a Python exception message. That's command line help output.
The output is generated by the argparse
module, configured here:
def main():
# parse arguments
parser = argparse.ArgumentParser(description='InstaRaider')
parser.add_argument('username', help='Instagram username')
parser.add_argument('directory', help='Where to save the images')
parser.add_argument('-n', '--num-to-download',
help='Number of posts to download', type=int)
parser.add_argument('-l', '--log-level', help="Log level", default='info')
args = parser.parse_args()
The moment parser.parse_args()
is called your command line arguments are parsed to match the above configuration.
Specifically, the username
and directory
positional arguments are required:
parser.add_argument('username', help='Instagram username')
parser.add_argument('directory', help='Where to save the images')
You'll need to specify these on the command line when you run the script:
Google_Map.py some_instagram_username /path/to/directory/to/save/images
The other command line options are optional and start with -
or --
.
If you can't run this from a console or terminal command line, you could pass in the options to the parser directly:
def main(argv=None):
# parse arguments
parser = argparse.ArgumentParser(description='InstaRaider')
parser.add_argument('username', help='Instagram username')
parser.add_argument('directory', help='Where to save the images')
parser.add_argument('-n', '--num-to-download',
help='Number of posts to download', type=int)
parser.add_argument('-l', '--log-level', help="Log level", default='info')
args = parser.parse_args(argv)
# ....
main(['some_instagram_username', '/path/to/directory/to/save/images'])
Now the arguments are passed in via the argv
optional function parameter, as a list.
However, rather than have main()
parse arguments, you could just use the InstaRaider()
class directly:
raider = InstaRaider('some_instagram_username', '/path/to/directory/to/save/images')
raider.download_photos()