From 869474e8e6a3e5a226e0063623ddc1c7c37ad211 Mon Sep 17 00:00:00 2001 From: Idan Cohen Date: Sat, 12 Nov 2022 15:41:15 +0200 Subject: [PATCH] add download all package function --- npm_install.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/npm_install.py b/npm_install.py index 891dac0..05223fc 100644 --- a/npm_install.py +++ b/npm_install.py @@ -1,9 +1,8 @@ -from os import system +from os import system, mkdir from re import findall from sys import argv import requests - def npm_create_package_lock_file(package): system("npm i --package-lock-only " + package) @@ -15,8 +14,17 @@ def get_all_urls_packages(): def download_npm_package(url:str, path="./"): - with open(path + url.split("/")[-1], "wb") as npm_package_file: - npm_package_file.write(requests.get(url)) + try: + with open(path + url.split("/")[-1], "wb") as npm_package_file: + npm_package_file.write(requests.get(url)) + except: + raise "Path not exist!\nPlease create the path: " + path + + +def download_all_package(): + packages_urls = get_all_urls_packages() + for package_url in packages_urls: + download_npm_package(package_url, "npm-packages/") def main():