My task was to create a Python script and connect to various TLS sites and grab the expiry dates. I've done this with openssl and ssl modules just fine.
In my mind I was wanting to create a web page as a dashboard.
I've done that.
It's as simple as it gets I think (which I am happy with):
But I ended up doing a for loop of the dictionary I stored the values for expiration, url, and status.
with open(htmlfile,'a') as fh: for urlandport,data in urldict.items(): url,tcpport = urlandport msg,status = data #print(url) if status == 'OK': delta = data - now days_left = str(abs(delta.days)) color = 'green' if int(days_left) > 400 \ else 'orange' if int(days_left) < 100 \ else 'red' sclr = 'green' else: days_left = 'NA' expiration = 'NA' color = 'blue' sclr = 'blue' msg,status = status,msg #Swap dashboard order on failure fh.write( "<tr>" + "<td>" + url + " " + str(tcpport) + "</td>" + \ "<td><font color="+color+">"+days_left+"</font>"+"</td>" + \ "<td><font color="+color+">"+ str(msg)+"</font>"+"</td>" + \ "<td><font color="+sclr+">"+str(status)+"</font>"+"</td>"+"</tr>" )
In my mind this does not seem very modern or flexible to proceed in manually cobbling HTML like this. It works. But I am wondering if I should invest in learning something more suitable for scalability.
I was also also to separate out the certs into 4 different tables: soon to expire, OK for now, connect failure and too old to bother and display then in a particular order for the user.
Hence, I ended up just creating 4 lists and appending to them so I could loop over each as I chose.
It just feels like I wrote some eye searing python to cobble something together...I am not even sure if a "Web Framework" would help or frankly why...I've looked into some of them but it's not sinking in.