Inventory HTML page to a CSV file

January 07, 2023

As a New Year’s resolution, not mine, they wanted to make sure their online store, reseller site, inventory was up to date. They wanted to make sure their inventory was cleaned up and make sure that what’s listed on the site matches their own inventory. They had been doing this for several years, with different people helping out at times; this isn’t there full-time job.

They needed a spreadsheet with the important info of their inventory, they couldn’t find a way to get a spreadsheet from their online reseller location and asked me late on Dec. 31 if I could create one from the HTML files they downloaded by Jan 3. This only gave me 2 days along with another New Year’s resolution project for somebody else to get done.

The request:

The spreadsheet needed to show:
The item name; Quantity; SKU #; Status
Needed to be open in Excel
Had to get it done within 2 days

This project is more about turning code around quickly, a lot of the time you don’t have a lot of time to create the program, you just need to get it done. In cases like that you work to get the code to work then if you have time go back and clean it up as much as you can.

When planning this out the first thought was, I had started to play with Selenium. This would cause too many issues I would need their password, then if there’s a 2nd verification system has to work with them to get that through. With how little they might be using this, the site might change so much by the next time that it would need rewritten and tested again, where just using the HTML files and update code, if needed, would be a faster approach.

First I decided to create a CSV file, Excel will open this file, and used some of the code I had already wrote for the gathering email addresses program:
https://www.lynnamacher.com/python-pull-email-addresses-to-csv-file/
This way I would have the basic structure setup for creating the CSV file right from the beginning.

Looking through the code I found that the elements ‘Item name’, ‘Quantity’ and ‘SKU’ where all on the same line. That made getting those easier then set the trigger for the line and pulled each element out into its separate variables. The ‘Status’ was off on its own line so had to check for that separately; this could have caused issues if these ‘Status’ words were used at the beginning of other lines.

The first big hurdle that happens when writing these to the CSV file it converted them into tuples with each blank elements so I would get 2 tuples like this: (‘Item Name’, ‘Quantity’, ‘SKU’, ‘’, ‘’) (‘’,  ’’, ’’, ’Status’). I worked with this for a time then converted the saves to add them to a list and then process the list when done. I might have been able to run over the tuples checking for non-null areas then pull those to write. This won’t work very well if we were looking at hundreds of pages to process, but for these few it was fine.

When processing the list, I pulled the items out and increased the count by 1 at the end of each element to help keep track quicker. If there would have been times where there could be empty values passed, I could have looked as lists inside the list, or pass a blank (‘’). Then wrote the line and pulled the next from the list that has already been counted out. There’s a lot I could have cleaned up here, but it’s easy to read and a simple enough program to read through.

In the end I was able to get both projects done before Tuesday, Jan. 3. While it might not be the best written or cleanest code, it’s working code. For simple one-time projects this is what is needed, the clients won’t want to pay you for hours of making it clean and showing off how you can have 20 lines of code written in 1 line; mostly they won’t care how it looks for a simple one-time project as long as it works. If running on a server, part of a bigger application or for another programmer which this isn’t, then having code cleaned up and able to be processed fast using as few resources is preferred, where spending the extra time is needed.

Git: https://github.com/amacher/inventoryCSV/blob/main/Inv_GIT.py

Related Articles

Website Contact form using AWS

Website Contact form using AWS

For the next iteration of the HTML form was to set it up to send an email to the web owner using AWS. The purpose behind this is, if you have a HTML site and don’t want to purchase a monthly plan or build and maintain server software. Using AWS for this functionality...

read more
HTML with JavaScript contact form

HTML with JavaScript contact form

Link to the form: https://www.lynnamacher.com/pdf/contactForm_V1.html This is created to be basic test for an AWS contact form test. The full form when filled out will send an email through AWS to the site owner. Instead of creating the normal test form I try to...

read more
Sometimes the low-tech approach is the best way

Sometimes the low-tech approach is the best way

Have a family member looking to get me some family videos they had digitized, in one big file, about 80GB (they may not have optimized or know how). The need: The family member’s internet connection isn’t the best and could get disconnected at times, when this happens...

read more

Pin It on Pinterest

Share This