I have a script that uses bs4 to scrape a webpage and grab a string named, "Last Updated 4/3/2020, 8:28 p.m.". I then assign this string to a variable and send it in an email. The script is scheduled to run once a day. However, the date and time on the website change every other day. So, instead of emailing every time I run the script I'd like to set up a trigger so that it sends only when the date is different. How do I configure the script to detect that change?
<SPAN class="string token">'''Checks municipal websites for changes in meal assistance during C19 pandemic'''</SPAN>
<SPAN class="comment token"># Import requests (to download the page)</SPAN>
<SPAN class="keyword token">import</SPAN> requests
<SPAN class="comment token"># Import BeautifulSoup (to parse what we download)</SPAN>
<SPAN class="keyword token">from</SPAN> bs4 <SPAN class="keyword token">import</SPAN> BeautifulSoup
<SPAN class="comment token"># Import win32com (Python module that controls Outlook)</SPAN>
<SPAN class="keyword token">import</SPAN> win32com<SPAN class="punctuation token">.</SPAN>client
<SPAN class="keyword token">from</SPAN> win32com<SPAN class="punctuation token">.</SPAN>client <SPAN class="keyword token">import</SPAN> Dispatch<SPAN class="punctuation token">,</SPAN> constants
<SPAN class="keyword token">import</SPAN> re
<SPAN class="keyword token">import</SPAN> urllib
<SPAN class="keyword token">import</SPAN> urllib<SPAN class="punctuation token">.</SPAN>request
<SPAN class="comment token">#list of urls</SPAN>
urls <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'http://www.vofil.com/covid19_updates'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#set the headers like we are a browser</SPAN>
headers <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">'User-Agent'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">#download the homepage</SPAN>
response <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN>urls<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> headers<SPAN class="operator token">=</SPAN>headers<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#parse the downloaded homepage and grab all text</SPAN>
soup <SPAN class="operator token">=</SPAN> BeautifulSoup<SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">.</SPAN>text<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"lxml"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Find string</SPAN>
last_update_fra <SPAN class="operator token">=</SPAN> soup<SPAN class="punctuation token">.</SPAN>findAll<SPAN class="punctuation token">(</SPAN>string<SPAN class="operator token">=</SPAN>re<SPAN class="punctuation token">.</SPAN>compile<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Last Updated"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>last_update_fra<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Put something here (if else..?) to trigger an email.</SPAN>
<SPAN class="comment token">#I left off email block...</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Here's where the string is in the HTML:
<SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>h1</SPAN><SPAN class="punctuation token">></SPAN></SPAN>COVID-19 News Updates<SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>h1</SPAN><SPAN class="punctuation token">></SPAN></SPAN>
<SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>div</SPAN><SPAN class="punctuation token">></SPAN></SPAN><SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>br</SPAN><SPAN class="punctuation token">></SPAN></SPAN><SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>div</SPAN><SPAN class="punctuation token">></SPAN></SPAN><SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>div</SPAN><SPAN class="punctuation token">></SPAN></SPAN>Last Updated 4/3/2020, 12:08 p.m.<SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>div</SPAN><SPAN class="punctuation token">></SPAN></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>