from ftplib import FTP import requests import minify_html from os import listdir, getenv, chdir from io import BytesIO # init ftp print(getenv('FTP_SERVER')) ftp = FTP(getenv('FTP_SERVER')) ftp.login(getenv('FTP_USER'), getenv('FTP_PASSWORD')) chdir('html') for f in [i for i in listdir() if i.endswith('.html')]: # 1. Minify the index.html file using minify-html minified_content = minify_html.minify(open(f, 'r').read(), minify_css=True, do_not_minify_doctype=True) # 2. Upload the file to an FTP server ftp.storbinary('STOR ' + f, BytesIO(minified_content.encode())) ftp.storbinary('STOR geofeed.csv', BytesIO(open('../geofeed.csv', 'r').read().encode())) # refresh cache url = 'https://api.bunny.net/purge?url=https%3A%2F%2Fdn42.724.rocks&async=false' # replace with your URL headers = { 'AccessKey': getenv("ACCESS_KEY") } response = requests.get(url, headers=headers) # Quit ftp ftp.quit()