def update_files(x, y): file_name = x print(file_name) save_logs.log(file_name) headers = { "Connection": "keep-alive", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "accept-encoding": "gzip, deflate, br", "accept-language": "en-GB,en-US;q=0.9,en;q=0.8", "cache-control": "max-age=0" } r = requests.get(y, allow_redirects=True, headers=headers, timeout=10) web_documents = ['index.html', 'main.js', 'style.css'] if file_name in web_documents: location = f"web\\{file_name}" with open(location, 'wb') as f: f.write(r.content) else: with open(file_name, 'wb') as f: f.write(r.content) printed_update(f"{file_name} updated")
def call_for_update(): # Calls Photon to Update the Files photon.main() try: # Attempts to save logs (If file indeed exists and is working, should be fine) save_logs.log("Checking files...") printed_update("Files Verified. System is ready.") except: # Restores files from local backup because error detected in updated files restore_backup() printed_update("Localised Verified. System is ready.")
def printed_update(update): print(update) main_update(update) save_logs.log(update)