import os,requests,json,time,sys,argparse,psutil Log="" UA={'User-Agent':'GeMCAPI/6.0.0 (GeMC API Sync 6.0.0;Release)'} parser=argparse.ArgumentParser() parser.add_argument("--url", help="The online url of the file which need to download.") parser.add_argument("--file", help="The file path of the file which need to download.") parser.add_argument("--other", help="Other parameter which help some special file to download correctly.") parser=parser.parse_args() proxies={'http':'http://127.0.0.1:4780'}#Proxy Setting def log(log_type,logvar): global Log if(log_type=="info"): log_type="INFO" elif(log_type=="warn"): log_type="WARN" elif(log_type=="error"): log_type="ERROR" Log=Log + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[' + log_type + ']' + logvar def download(url, dirpath): global Log global UA log("info",'We are downloading the file ' + dirpath + '.') try: download=requests.get(url, headers=UA, proxies=proxies) with open(dirpath,"wb") as code: code.write(download.content) except: log("error",'There has a error in task while downloading the file ' + dirpath + '.') else: log("info",'The file ' + dirpath + ' has been downloaded successfully.') def make_dir_exist(dirpath): global Log if os.path.exists(dirpath): log("info",'The dir ' + dirpath + ' has already existed.Nothing to do.') else: log("info",'The dir ' + dirpath + ' does not exist.We will create one.') os.makedirs(dirpath) print(round(float(time.time())))