How to use download_and_extract method in localstack

Best Python code snippet using localstack_python

download_gtacrash.py

Source:download_gtacrash.py Github

copy

Full Screen

...21 f.write(chunk)22def mkdir(path):23 if not os.path.exists(path):24 os.makedirs(path)25def download_and_extract(file_id, dst, final_dst, level=1):26 print("downloading {}...".format(dst))27 download_file_from_google_drive(file_id, dst)28 print("download completed!")29 print("extracting...")30 mkdir(final_dst)31 mkdir("./datasets/temp")32 os.system("tar -xf {} --strip-components={} -C ./datasets/temp".format(dst, str(level)))33 files = os.listdir("./datasets/temp/")34 for f in files:35 shutil.move("./datasets/temp/"+f, final_dst)36 os.system("rm -r ./datasets/temp")37 print("extraction completed!")38 os.system("rm {}".format(dst))39 print("zip file removed")40if __name__ == "__main__":41 # Accident Images Part 142 file_id = str("1xTqFxguYxvF8zf7_e_clAq2GTq1Wi3vC")43 dst = str("./datasets/GTACrash_accident_images_part1.tar.gz")44 final_dst = str("./datasets/GTACrash/accident")45 download_and_extract(file_id, dst, final_dst)46 # Accident Images Part 247 file_id = str("1K_wEYFvyqMI_Dq_Au8d97Fb23RgCzS40")48 dst = str("./datasets/GTACrash_accident_images_part2.tar.gz")49 final_dst = str("./datasets/GTACrash/accident")50 download_and_extract(file_id, dst, final_dst)51 # Accident Images Part 352 file_id = str("1JjuJ-h670FWYsaZ5V7XMGPNg8QNertRU")53 dst = str("./datasets/GTACrash_accident_images_part3.tar.gz")54 final_dst = str("./datasets/GTACrash/accident")55 download_and_extract(file_id, dst, final_dst)56 # Nonaccident Images Part 157 file_id = str("1fSEqEvhDm-vKm4ZPSddn08w6NuV3Zm4l")58 dst = str("./datasets/GTACrash_nonaccident_images_part1.tar.gz")59 final_dst = str("./datasets/GTACrash/nonaccident")60 download_and_extract(file_id, dst, final_dst)61 # Nonaccident Images Part 262 file_id = str("1Q8xQMWrdbzSTjCa8Cr68Cnx1gN5DxTfP")63 dst = str("./datasets/GTACrash_nonaccident_images_part2.tar.gz")64 final_dst = str("./datasets/GTACrash/nonaccident")65 download_and_extract(file_id, dst, final_dst)66 # Accident Labels Part 167 file_id = str("1LKHVBPeadPzbMZjsXyALD0ERMyayq1vv")68 dst = str("./datasets/GTACrash_accident_labels_part1.tar.gz")69 final_dst = str("./datasets/GTACrash/accident")70 download_and_extract(file_id, dst, final_dst, level=2)71 # Accident Labels Part 272 file_id = str("1CJmC21G4UOM1B2WnMax_aIkvk9X-Ho-R")73 dst = str("./datasets/GTACrash_accident_labels_part2.tar.gz")74 final_dst = str("./datasets/GTACrash/accident")75 download_and_extract(file_id, dst, final_dst, level=2)76 # Accident Labels Part 377 file_id = str("1Ikgkpl4EbZga2IrymInWlzyUmuWNK9eB")78 dst = str("./datasets/GTACrash_accident_labels_part3.tar.gz")79 final_dst = str("./datasets/GTACrash/accident")80 download_and_extract(file_id, dst, final_dst, level=2)81 # Nonaccident Labels Part 182 file_id = str("13G_MUZ00dw12YhJE-oxCI0KeH8UGzoWR")83 dst = str("./datasets/GTACrash_nonaccident_labels_part1.tar.gz")84 final_dst = str("./datasets/GTACrash/nonaccident")85 download_and_extract(file_id, dst, final_dst, level=2)86 # Nonaccident Labels Part 287 file_id = str("1zNs9YUDzXzYLuUunTCmQQPCHm51qjHHv")88 dst = str("./datasets/GTACrash_nonaccident_labels_part2.tar.gz")89 final_dst = str("./datasets/GTACrash/nonaccident")...

Full Screen

Full Screen

download.py

Source:download.py Github

copy

Full Screen

1"""Download datasets supported by MusPy."""2import argparse3import warnings4from pathlib import Path5import muspy6DATASET_KEYS = [7 "essen",8 "hymnal",9 "hymnal_tune",10 "jsb",11 "lmd",12 "maestro",13 "nes",14 "nmd",15 "wikifonia",16]17def download(key, root):18 """Download the specified dataset."""19 if key == "lmd":20 muspy.LakhMIDIDataset(root, download_and_extract=True)21 elif key == "wikifonia":22 muspy.WikifoniaDataset(root, download_and_extract=True)23 elif key == "nes":24 muspy.NESMusicDatabase(root, download_and_extract=True)25 elif key == "jsb":26 muspy.JSBChoralesDataset(root, download_and_extract=True)27 elif key == "maestro":28 muspy.MAESTRODatasetV2(root, download_and_extract=True)29 elif key == "hymnal":30 muspy.HymnalDataset(root, download=True)31 elif key == "hymnal_tune":32 muspy.HymnalDataset(root, download=True)33 elif key == "nmd":34 muspy.NottinghamDatabase(root, download_and_extract=True)35 elif key == "essen":36 muspy.EssenFolkSongDatabase(root, download_and_extract=True)37 else:38 warnings.warn(39 "Skipped unrecognized dataset identifier : {}.".format(key),40 RuntimeWarning,41 )42def parse_args():43 """Parse command line arguments."""44 parser = argparse.ArgumentParser(description="Download datasets")45 parser.add_argument("root", help="Root directory to store the dataset(s).")46 parser.add_argument("datasets", nargs="*", help="Dataset identifier(s).")47 parser.add_argument(48 "-a",49 "--all",50 action="store_true",51 help="Download all supported datasets.",52 )53 return parser.parse_args()54def main():55 """Download datasets."""56 args = parse_args()57 root = Path(args.root)58 if not root.is_dir():59 raise FileNotFoundError("Root directory must exist.")60 if args.all:61 for dataset in DATASET_KEYS:62 (root / dataset).mkdir(exist_ok=True)63 download(dataset, root / dataset)64 else:65 for dataset in args.datasets:66 (root / dataset).mkdir(exist_ok=True)67 download(dataset.lower(), root / dataset)68if __name__ == "__main__":...

Full Screen

Full Screen

get_omb_data.py

Source:get_omb_data.py Github

copy

Full Screen

...3import urllib4import zipfile5from util import configuration6omb_path = configuration.get_path_to_omb_data()7def download_and_extract(url):8 path_to_new_zip = os.path.join(omb_path,url.split("/")[-1])9 urllib.urlretrieve(url, path_to_new_zip)10 zfile = zipfile.ZipFile(path_to_new_zip)11 zfile.extractall(omb_path)12def get_2010_earmarks():13 url= "http://earmarks.omb.gov/earmarks-public/resources/downloads/2010-appropriation-earmark-extract.zip"14 download_and_extract(url)15 os.rename(os.path.join(omb_path, "2010-appropriations-earmark-extract.csv"), os.path.join(omb_path, "2010.csv"))16def get_2009_earmarks():17 url= "http://earmarks.omb.gov/earmarks-public/resources/downloads/2009-appropriations-earmark-extract.zip"18 download_and_extract(url)19 os.rename(os.path.join(omb_path, "2009-appropriations-earmark-extract.csv"), os.path.join(omb_path, "2009.csv"))20def get_2008_earmarks():21 url= "http://earmarks.omb.gov/earmarks-public/resources/downloads/2008-appropriation-earmark-extract.zip"22 download_and_extract(url)23 os.rename(os.path.join(omb_path, "database.csv"), os.path.join(omb_path, "2008.csv"))24def get_2005_earmarks():25 url= "http://earmarks.omb.gov/earmarks-public/resources/downloads/appropriation-earmark-extract.zip"26 download_and_extract(url)27 os.rename(os.path.join(omb_path, "database.csv"), os.path.join(omb_path, "2005.csv"))28def main():29 if not os.path.exists(omb_path):30 os.makedirs(omb_path)31 get_2010_earmarks()32 get_2009_earmarks()33 get_2008_earmarks()34 get_2005_earmarks()35if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful