Created
August 7, 2020 02:58
-
-
Save Gictorbit/448bbd1daa5a1e92eba072598cf3a5e9 to your computer and use it in GitHub Desktop.
a simple python script to download all dirvers for lenovo laptops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
from prettytable import PrettyTable | |
import os | |
def main(): | |
baseURL='https://pcsupport.lenovo.com/us/en/api/v4/downloads/drivers?productId=' | |
productID='laptops-and-netbooks/legion-series/legion-y540-15irh-pg0/81sy' | |
url=baseURL+productID | |
with requests.session() as session: | |
res = session.get(url=url) | |
resData = json.loads(res.content) | |
data = json.dumps(resData,indent=4) | |
primeryDir =resData.get('body').get('ProductId').split('-')[0] | |
allItems = resData.get('body').get('DownloadItems') | |
if not os.path.exists(primeryDir): | |
os.mkdir(primeryDir) | |
# table = PrettyTable | |
# table.field_names=['file','type','size','link'] | |
for catgr in resData.get('body').get('AllCategories'): | |
dirName=primeryDir+'/'+str(catgr).replace('/','-') | |
if not os.path.exists(dirName): | |
os.mkdir(dirName) | |
for item in allItems: | |
parentDir=str(item['Category']['Name']).replace('/','-') | |
for file in item.get('Files'): | |
if file.get('TypeString') == 'EXE': | |
filePath = os.getcwd()+'/'+primeryDir+'/'+parentDir | |
fileName=file['Name'].replace(' ','-')+'.exe' | |
if not os.path.isfile(filePath+'/'+fileName): | |
print(downloadDriver(fileName=fileName,url=file['URL'],path=filePath)) | |
print(count) | |
def downloadDriver(fileName:str,url:str,path:str): | |
command = f'aria2c "{url}" -o "{fileName}" -d "{path}"' | |
res = os.system(command) | |
return res | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, the request is failing, do you know where to find more information about the API?