dn42-info/deploy.py
Minecon724 73e63a9f48
All checks were successful
/ deploy (push) Successful in 19s
you think I deserve that?
2024-05-12 18:33:25 +02:00

36 lines
No EOL
936 B
Python

from ftplib import FTP
import requests
import minify_html
from os import listdir, getenv, chdir
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')]:
# 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()