Skip to content

Instantly share code, notes, and snippets.

@davecoutts
Last active December 9, 2023 05:05
Show Gist options
  • Save davecoutts/3b5d79ce50c8214e8cf598c4016b609d to your computer and use it in GitHub Desktop.
Save davecoutts/3b5d79ce50c8214e8cf598c4016b609d to your computer and use it in GitHub Desktop.
Python script for collecting and displaying Dell Laptop/PC driver release information
DESCRIPTION = \
'''
#--------------------------------------------------------------------------------------------------
Collect and display Dell Laptop/PC driver release information.
#--------------------------------------------------------------------------------------------------
'''
EPILOG = \
'''
#--------------------------------------------------------------------------------------------------
This script will collect and display Dell Laptop/PC driver release information by making a call to
the same API that the Dell driver support web page uses.
The script requires two input values.
'productcode'. Which is the Dell API product name for the device.
'oscode' . Which is the Dell API code for the Operating System you wish to filter by.
The example below will collect the Windows 11 driver info for a Dell Inspiron 16 Plus 7610.
python3 dell_getdriversbyproduct.py --productcode inspiron-16-7610-laptop --oscode W2021
You can get the 'productcode' and 'oscode' for your device by inspecting their values on the Dell
driver support page, as below.
- Browse to the driver support web page for your device.
e.g. https://www.dell.com/support/home/en-uk/product-support/product/inspiron-16-7610-laptop/drivers
- Select the Operating System.
- Right mouse button 'Inspect' the web page to open the Browser Developer Tools.
- Go to the 'Network' tab in Developer Tools.
- Refresh the driver support web page.
- Filter the urls by the text 'fetchdriversbyproduct'.
- Copy the 'productcode' and 'oscode' values encoded in the 'fetchdriversbyproduct' url.
Below is an example 'fetchdriversbyproduct' url.
https://www.dell.com/support/driver/en-us/ips/api/driverlist/fetchdriversbyproduct?productcode=xps-13-9310-laptop&oscode=WT64A&lob=XPS&initialload=true&_=1636285462583
Example oscode mapping,
oscode = 'WT64A' # Windows 10
oscode = 'W2021' # Windows 11
oscode = 'UBT20' # Ubuntu 20.04 LTS
oscode = 'NAA' # Not Applicable
#--------------------------------------------------------------------------------------------------
The 'get_drivers' function outputs a list of dictionaries and can be called from another script,
as so,
from dell_getdriversbyproduct import get_drivers
data = get_drivers('inspiron-16-7610-laptop', 'W2021')
print(dict(data[0]))
{'Release Date': datetime.date(2021, 10, 29),
'Last Update': datetime.date(2021, 10, 29),
'Update Status': 'Recommended',
'Driver Version': '4.4.0, A00',
'Driver Name': 'Dell Update Windows Universal Application'}
#--------------------------------------------------------------------------------------------------
Briefly tested using,
- Python 3.9.7
- requests 2.26.0
- tabulate 0.8.9
The script is heavily based on baduker's excellent answer to stackoverflow question,
https://stackoverflow.com/questions/64684614
#--------------------------------------------------------------------------------------------------
'''
#--------------------------------------------------------------------------------------------------
__author__ = 'Dave Coutts'
__license__ = 'Apache'
__version__ = '1.0.1'
__maintainer__ = 'https://github.com/davecoutts'
__status__ = 'Production'
#--------------------------------------------------------------------------------------------------
import time
import warnings
from datetime import datetime
from collections import OrderedDict
import requests # pip install requests
#------------------------------------------------------------------------------
def get_drivers(productcode, oscode, country='en-us'):
api_url = f'https://www.dell.com/support/driver/{country}/ips/api/driverlist/fetchdriversbyproduct'
headers = {
'Accept': 'application/json',
'x-requested-with': 'XMLHttpRequest'
}
parameters = {
'productcode': productcode,
'oscode': oscode,
'initialload': True,
'_': time.time() * 1000,
}
resp = requests.get(api_url, params=parameters, headers=headers)
if resp.status_code == requests.codes.ok:
driver_info = resp.json()
else:
warnings.warn(f'Collection error: {resp.status_code} {resp.reason} {resp.url}')
return []
data = []
for driver in driver_info['DriverListData']:
data.append(
OrderedDict([
['Release Date', datetime.strptime(driver['ReleaseDate'], '%d %b %Y').date()],
['Last Update', datetime.strptime(driver['LUPDDate'], '%d %b %Y').date()],
['Update Status', driver['Imp']],
['Driver Version',driver['DellVer']],
['Driver Name', driver['DriverName']]
]))
return data
#------------------------------------------------------------------------------
def main():
import argparse
from operator import itemgetter
from tabulate import tabulate # pip install tabulate
#------------------------------------------------------------------------------
parser = argparse.ArgumentParser(
epilog=EPILOG,
description=DESCRIPTION,
formatter_class=argparse.RawTextHelpFormatter
)
parser.add_argument('-p', '--productcode', dest='productcode', type=str, required=True)
parser.add_argument('-o', '--oscode', dest='oscode', type=str, required=True)
parser.add_argument('-c', '--country', dest='country', type=str, default='en-us')
args = parser.parse_args()
#------------------------------------------------------------------------------
data = get_drivers(args.productcode, args.oscode, args.country)
data = sorted(data, key=itemgetter('Release Date'), reverse=True)
#------------------------------------------------------------------------------
print(f'\nhttps://www.dell.com/support/home/{args.country}/product-support/product/{args.productcode}/drivers')
print(f'productcode: {args.productcode}')
print(f'oscode: {args.oscode}')
print(f'country: {args.country}\n')
print(tabulate(data, headers='keys', tablefmt='presto'))
#------------------------------------------------------------------------------
if __name__ == '__main__':
main()
#------------------------------------------------------------------------------
@jorgeavergara522
Copy link

Hi Dave,

This is great. How would I be able to execute this? Can I do it through an online compiler? Can I use command prompt? I am such a rookie.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment