Python script for automating static web page content update. Change code as needed.
When I was given many static web pages of a small business and was asked to create more for their new products
- Python + library: openxyl, panda
- Json
- CSV
- Excel
- write category csv file or directly change an existed category json file.
- If write csv file, run:
python category_json_generator.py source.csv
- Find product image source folder, excel file path, and add into info_organizer.py file, last line
- Open excel file, run:
If space in the excel filename cannot avoid, change the code and hardcode it.
python info_organizer.py
- follow instructions, enter data positions, keep all character lowercase
- get item_dict.json, images moved to structured folders
- In "page_template.html", set up the template for product pages for content to change.
- In "slider_img_block.html", set up the slider image code template used on product page.
- In "category_item_block.html", set up item code block on category page template.
- In "search_template.txt", set up search entry template.
Tags used in item page:
#itemCetegory#, #itemID#, #itemColor#, #itemDesription#, #itemPrice#, #backToCategoryPageURL#, #slider_images#
Tags used in slider image code block:
#image_path#
Tag used in category item code block and search code blcok entry:
#itemID#, #htmlFile#, #profileImage#
- Run:
python content_generator.py
- Individual item pages generated, move to the website folder to check result. (if you use js on the website)
- Put the code in "category_item_block_output.txt" manually in to corredponsing position on category page. The category page code differs and contaisn existed code, manually works for now.
- Copy paste the content of "search_block.txt" after the existed serach entries.
- One the webpage, find a good piece of code for replacement. put into "old.txt".
- Put the existed code + code to add into "new.txt".
- Put "update_files.py" in the same folder with webpage files, run:
python update_files.py old.txt new.txt
- To check if update exists in files, put new content into "content_to_check.txt", put "check_file_updated.py" in the same folder with webpages, run:
python check_file_updated.py content_to_check.txt
- The check result for every file will be print out.
- If the piectures on the webpage is too big and make it slow to load, shrink the size of all pictures under a directory if its width is more than 1000px
- Run:
python shrink_imgs.py imgs_directory
- Repeat runnig the script until no messages shows up
- Find the locaion to put content in the template file, put marker
- Find the start and end location of the content that need to be copied from the source webpage
- Add markers, directories, templates in the script "item_page_mover.py"
- Run:
python item_page_mover.py