def demsize(path, infile): results = [] summation = 0 spc = psutil.disk_usage(path).free remain = float(spc) / 1073741824 # now start downloading each file try: with fiona.open(infile) as input: for pol in input: reader = pol['properties']['fileurl'] download_url = reader pool = PoolManager() response = pool.request("GET", download_url, preload_content=False) max_bytes = 100000000000 content_bytes = response.headers.get("Content-Length") summary = float(content_bytes) / 1073741824 summation = summation + summary print(format(float(summation), '.2f'), "GB", end='\r') else: result = False except KeyError: print('Could not check size') #print(remain,"MB") print("Remaining Space in GB", format(float(remain), '.2f')) print("Total Download Size in GB", format(float(summation), '.2f'))
def demsize(ftype, infile): choicelist = [ "Go grab some tea.....", "Go Stretch.....", "Go take a walk.....", "Go grab some coffee.....", ] # adding something fun print("This might take sometime. {}".format(random.choice(choicelist))) summation = [] try: if infile.endswith(".csv"): with open(infile, "r") as csvfile: reader = csv.reader(csvfile) ulist = [row[0] for row in reader] elif infile.endswith(".shp") and ftype is not None: ulist = selection(ftype, infile, extract_file=None) elif infile.endswith(".shp") and ftype is None: sys.exit("Pass an ftype: Strip or Tile") print("Processing a total of {} objects in File URL list".format( len(ulist))) for download_url in ulist: pool = PoolManager() response = pool.request("GET", download_url, preload_content=False) max_bytes = 1000000000000 content_bytes = response.headers.get("Content-Length") summation.append(float(content_bytes)) print("Estimated Total Size: {}".format(humansize(sum(summation))), end="\r") except KeyError: print("Could not check size") print("\n" + "Total Download Size: {}".format(humansize(sum(summation))))
def process_size(path, id_list, item_type, asset_type, overwrite): results = [] summation = 0 path = args.size spc = psutil.disk_usage(path).free remain = float(spc) / 1073741824 # now start downloading each file for item_id in id_list: url = ASSET_URL.format(item_type, item_id) logging.info('Request: {}'.format(url)) result = SESSION.get(url) check_status(result) try: if result.json()[asset_type]['status'] == 'active': download_url = result.json()[asset_type]['location'] #print(download_url) pool = PoolManager() response = pool.request("GET", download_url, preload_content=False) max_bytes = 100000000000 content_bytes = response.headers.get("Content-Length") print("Item-ID: " + str(item_id)) #print(int(content_bytes)/1048576,"MB") summary = float(content_bytes) / 1073741824 summation = summation + summary print(format(float(summation), '.2f'), "GB", end='\r') #print ("Total Size in MB",summation) else: result = False except KeyError: print( 'Could not check activation status - asset type \'{}\' not found for {}' .format(asset_type, item_id)) result = False results.append(result) #print(remain,"MB") print("Remaining Space in MB", format(float(remain * 1024), '.2f')) print("Remaining Space in GB", format(float(remain), '.2f')) print("Total Size in MB", format(float(summation * 1024), '.2f')) print("Total Size in GB", format(float(summation), '.2f')) return results