There's a link on our website that leads to a zip folder. The line in the HTML file for it is shown thus:
<p><a href="Data/WillCounty_AddressPoint.zip">Address Points</a> (updated weekly)</p>
The zip folder's name will soon be changed using the current date so that it looks like this:
WillCounty_AddressPoint_02212018.zip
How do I change the corresponding line in the HTML?
Using this answer I have a script. It runs with no errors but does not change anything in the HTML file.
import bs4
from bs4 import BeautifulSoup
import re
import time
data = r'\\gisfile\GISstaff\Jared\data.html' #html file location
current_time = time.strftime("_%m%d%Y") #date
#load the file
with open(data) as inf:
txt = inf.read()
soup = bs4.BeautifulSoup(txt)
#create new link
new_link = soup.new_tag('link', href="Data/WillCounty_AddressPoint_%m%d%Y.zip")
#insert it into the document
soup.head.append(new_link)
#save the file again
with open (data, "w") as outf:
outf.write(str(soup))
current_time = time.strftime("_%m%d%Y") #date).time.strftime("_%m%d%Y")gives you an invalid file name 6 days out of 7 for the week?