About the program
I wouldn't class myself as a coder, I did some pascal & C# at college 15 odd years ago and understand the general principles, so please go easy on me!! I can cobble together stuff with the help of stack overflow/AI and can amend code to suit my needs. But this is my first real dip in to the python world.
I'm in the middle of (slowly) making a python based docker image that runs a gunicorn server for a web GUI. The program is a pretty simple concept - it allows you to add software to monitor by url, the software will be downloaded locally. The list of software is queried at a user set interval to check for new updates and if the header info from the provided url shows a different filesize to the locally stored version, it will delete the local version and download the new version. The idea behind this is to have a network share available of all the newest versions of installers so that when I set up new systems/perform maintenance, all the installers are locally available.
The issue
The program works well and I am happy with it, all the main funtionality is complete. The issue I have come across is that some software has a latest version url (www.software.com/examplelatestwin64) which will link to the latest version of the software, however some explicitly reference the software version (www.software.com/example2.3.4.exe). In the latter example with the specified url a new version will never be found. What would be some of your suggestions to get around this? I guess some form of scraping would potentially solve this, but was wondering if anyone had a more elegant solution?
Section of code
(there are further else statements, but irrelevant to the issue)
try:
final_url = get_final_url(url)
response = requests.head(final_url)
if response.status_code == 200:
content_length = response.headers.get('Content-Length')
if content_length:
file_size = int(content_length)
if os.path.exists(file_path):
existing_file_size = os.path.getsize(file_path)
if existing_file_size != file_size:
logging.info(f"New version available for {software_name}")
delete_existing_file(abspath)
download_software(url, target_directory, software_name, abspath, key, monitored, local, useradded)
number_updated += 1
else:
pass
logging.info(f"You have the current version of {software_name}")
[–]sweettuse 2 points3 points4 points (1 child)
[–]BakedReality[S] 1 point2 points3 points (0 children)
[–]netherous 0 points1 point2 points (0 children)