# pythonURLfetch.py
# Jim Miller, 9:31 PM Tue March 21, 2023

import requests
from requests.exceptions import Timeout
import codecs
import sys  

try:
    # This is used by geturl.pl to fetch the HMS page.
    response = requests.get("https://www.hanford.gov/c.cfm/hms/realtime.cfm", timeout=20, verify=False)
    
    with codecs.open('C:\\Users\\Jim\\Documents\\webcontent\\waconia\\urldump.txt', 'w', encoding=response.encoding) as file:
        file.write( response.text)
        
    print 'Request to Hanford page has succeeded.'
    
except Timeout:
    print 'Request to Hanford page has timed out.'
    
except:
    print 'Request to Hanford page has failed.'