def main():
    """Main method, entry point of the script."""
    from argparse import ArgumentParser
    description = "Download a bunch of thumbnails from Wikimedia Commons"
    parser = ArgumentParser(description=description)
    source_group = parser.add_mutually_exclusive_group()
    source_group.add_argument("-l", "--list", metavar="LIST",
                              dest="file_list",
                              type=argparse.FileType('r'),
                              help='A list of files <filename,width>')
    source_group.add_argument("-c", "--category", metavar="CATEGORY",
                              dest="category_name",
                              type=str,
                              help='A category name (without prefix)')
    parser.add_argument("files", nargs='*',
                        metavar="FILES",
                        help='A list of filenames')
    parser.add_argument("-o", "--output", metavar="FOLDER",
                        dest="output_path",
                        action=Folder,
                        default=os.getcwd(),
                        help='The directory to download the files to')
    parser.add_argument("-w", "--width",
                        dest="width",
                        type=int,
                        default=100,
                        help='The width of the thumbnail (default: 100)')
    verbosity_group = parser.add_mutually_exclusive_group()
    verbosity_group.add_argument("-v",
                                 action="count",
                                 dest="verbose",
                                 default=1,
                                 help="Verbosity level. -v for DEBUG")
    verbosity_group.add_argument("-q", "--quiet",
                                 action="store_const",
                                 dest="verbose",
                                 const=0,
                                 help="To silence the INFO messages")
    args = parser.parse_args()
    logging_map = {0: logging.WARNING,
                   1: logging.INFO,
                   2: logging.DEBUG}
    logging_level = logging_map.get(args.verbose, logging.DEBUG)
    logging.basicConfig(level=logging_level)
    logging.info("Starting")

    if args.file_list:
        download_from_file_list(args.file_list, args.output_path)
    elif args.category_name:
        download_from_category(args.category_name, args.output_path, args.width)
    elif args.files:
        download_from_files(args.files, args.output_path, args.width)
    else:
        parser.print_help()
def main ( ) : from argparse import ArgumentParser description = "Download a bunch of thumbnails from Wikimedia Commons" parser = ArgumentParser ( description = description ) source_group = parser . add_mutually_exclusive_group ( ) source_group . add_argument ( "-l" , "--list" , metavar = "LIST" , dest = "file_list" , type = argparse . FileType ( 'r' ) , help = 'A list of files <filename,width>' ) source_group . add_argument ( "-c" , "--category" , metavar = "CATEGORY" , dest = "category_name" , type = str , help = 'A category name (without prefix)' ) parser . add_argument ( "files" , nargs = '*' , metavar = "FILES" , help = 'A list of filenames' ) parser . add_argument ( "-o" , "--output" , metavar = "FOLDER" , dest = "output_path" , action = Folder , default = os . getcwd ( ) , help = 'The directory to download the files to' ) parser . add_argument ( "-w" , "--width" , dest = "width" , type = int , default = 100 , help = 'The width of the thumbnail (default: 100)' ) verbosity_group = parser . add_mutually_exclusive_group ( ) verbosity_group . add_argument ( "-v" , action = "count" , dest = "verbose" , default = 1 , help = "Verbosity level. -v for DEBUG" ) verbosity_group . add_argument ( "-q" , "--quiet" , action = "store_const" , dest = "verbose" , const = 0 , help = "To silence the INFO messages" ) args = parser . parse_args ( ) logging_map = { 0 : logging . WARNING , 1 : logging . INFO , 2 : logging . DEBUG } logging_level = logging_map . get ( args . verbose , logging . DEBUG ) logging . basicConfig ( level = logging_level ) logging . info ( "Starting" ) if args . file_list : download_from_file_list ( args . file_list , args . output_path ) elif args . category_name : download_from_category ( args . category_name , args . output_path , args . width ) elif args . files : download_from_files ( args . files , args . output_path , args . width ) else : parser . print_help ( )
Main method, entry point of the script.