dn42-info/deploy.py

36 lines
936 B
Python
Raw Normal View History

2024-05-12 16:45:33 +02:00
from ftplib import FTP
import requests
import minify_html
from os import listdir, getenv, chdir
2024-05-12 16:45:33 +02:00
from io import BytesIO
# init ftp
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')]:
2024-05-12 16:45:33 +02:00
# 1. Minify the index.html file using minify-html
2024-05-12 18:33:25 +02:00
minified_content = minify_html.minify(open(f, 'r').read(), minify_css=True, do_not_minify_doctype=True)
2024-05-12 16:45:33 +02:00
# 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()