Download on GitHub
This python script adds information on physical disks to a Microsoft Access database. The information is automatically retrieved from hddfaqs.com, using the model number of the disks scanned by the user.
The database is stored in .\DATABASE\Inventory.accdb
To use the script you have to install :
Microsoft Access
Python
The python architecture must be the same as that of Microsoft Access.
Python x64 <--> MS access x64
Python x86 <--> MS access x86
Microsoft Access database structure
TABLE NAME : DRIVES
Column
Type
ID_Drives
AutoIncrement
Model_Number
ShortText
Brand
ShortText
Storage_in_GB
Number
Size
ShortText
Serial_Number
LongText
Cache
ShortText
Date
ShortText
Country
ShortText
Tested
Yes/No
Interface
ShortText
Working
Yes/No
Label_notes
LongText
Miscelanious
LongText
Location
ShortText
Libraries :
Library
Usage
Requests
to fetch the datas from hddfaqs.com
BeautifulSoup
to parse the HTML page
re
to search and manipulate strings
pyodbc
for connection to the Microsoft Access database
You can install the libraries using the requirements.txt
Script logic
For the moment, hddfaqs doesn't offer an API for data retrieval. The script uses a WebScrapping technique, which consists in extracting the HTML elements of a page, and then retrieving the raw values.
To find the right drive, the script uses the search system to find the first result, then visits the new page for the data.
Try to connect to the database using the pyodbc library
Main loop
Now the URL is: https://hddfaqs.com/?s= + model_number
Then, the script tries out the entire script in safe mode. If there's an error somewhere, it displays the error but doesn't stop the script.
Still in safe mode, the script is using the requests lib to fetch the URL.
In the headers, we specify a user-agent to make the platform believe that we are an ordinary user.
In the result, the script attempts to obtain the first element. If it fails to do so, this means that the disk is not in the database, which interrupts the loop.
If successful, the URL has been modified by the url of the first element. The script retrieves the new page.
Retrieving disk information :
CAPACITY :
Sometimes on hddfaqs it can't work because on some pages the text is written with Ex: <li><strong>Storage Capacity: </strong>128 GB</li> and not Ex: <li>Capacity: 128GB</li> so the script can't read the value with this method. That's why it uses safe mode for this, because if it doesn't work, we try the second method, and if it still doesn't work, error...
so here is the second method :
The script needs the capacity unit beacause on some drives the values can switch between GB, TB, MB. And in the database we only want GB, so we have to convert the value :
BRAND :
For the brand this is the same way, first it tries to find an element like <li>Manufacturer: Toshiba</li>
If it can't it tries to find a <strong> element, select the next one, then the previous one.
SIZE :
Same method as BRAND
CACHE :
Finding the disk cache is a different method. The script selects the disk description ".desc1" because the cache is somewhere in the description. It therefore uses the re library to find the text "MB Cache". We then analyze the value just before it. If it finds something, we have the cache, otherwise the cache won't be in the database.
INTERFACE :
Finding the interface is the same method as BRAND and CACHE.
Some results have to be converted.
The script can't find certain information on its own using hddfaqs, such as serial number or date, country, location. It therefore asks the user to provide this information using the :
Finishing :
Finally, it displays all the drive information to the user. If all values are correct, it adds the drive to the database. If not, it requests the correct capacity and manufacturer.