1 From argparse import argumentparser 2 3 P = argumentparser (description = 'eg: $ Python mm_crawler-N 8-o "D: /mm_pics "-l 500 4 this command means that the your app will create 8 coroutines to download 500 pictures, and save them to D:/mm_pics ') 5 p. add_argument ("-n", type = int, help = "set number of coroutines (default: 10)", default = 10) 6 p. add_argument ("-o", type = STR, help = 'set pictures save path (default :. /pics/) ', default = ". /pics/") 7 p. add_argument ("-l", type = int, help = "Number of limits of picture to crawl (default: 0, no limit)", default = 0) 8 9 # P. print_help () 10 ARGs = P. parse_args () 11 ARGs = vars (ARGs) 12 13 # write these values to Conf. 14 with open ("Conf. PY ", 'wb') as conf_file: 15 conf_file.write (" Limit = % s \ n "% STR (ARGs ['l']) 16 conf_file.write ("p_thread_num = % s \ n" % STR (ARGs ['n']) 17 conf_file.write ("save_dir = '% s' \ n" % ARGs ['O']) 18 conf_file.close () 19 20 # print (ARGs)
Read and parse command line parameters