Created
November 7, 2022 14:21
-
-
Save Theasker/cb557fef7742f9505007db94daf07646 to your computer and use it in GitHub Desktop.
Actualización de una "Land Page" de los servicios docker usados con Caddy Docker Proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!./venv/bin/python3 | |
| import os | |
| # Buscamos los ficheros que cumplen la condición | |
| def find_files(dir, findFile, findText): | |
| for root, dir, files in os.walk(dir): | |
| for file in files: | |
| if(findFile in file.lower()): | |
| filePath=root+"/"+file | |
| # print(filePath) | |
| find_text(filePath, findText) | |
| # Buscamos los ficheros que cumplen la condición | |
| def find_text(file, textFind): | |
| # Leo línea a linea el fichero y compruebo | |
| with open(file, "r") as fie_read: | |
| arraylines = fie_read.readlines() | |
| # Leemos el fichero línea a línea | |
| for line in arraylines: | |
| line = line.rstrip() # Quitamos espacios de final de línea | |
| #lineSplit = line.split(" ") # Partimos la línea en partes separados por espacios | |
| if textFind in line: | |
| # Elimino información no necesaria | |
| line = line.replace("\"", "").strip().replace("caddy: ","") | |
| sites.append(line) | |
| def create_file(file, sites): | |
| try: | |
| f = open(file, 'w') | |
| html=""" | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Theasker Land page</title> | |
| <link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css"> | |
| <html data-theme="dark"> | |
| <body> | |
| <div class="grid"> | |
| <div> | |
| <article align="center"> | |
| <h1>Theasker services</h1>\n""" | |
| for site in sites: | |
| html = html + f" <a href=\"{site}\" role=\"button\" class=\"outline\">{site}</a><br>\n" | |
| html = html + """ </article> | |
| </div> | |
| </div> | |
| </body> | |
| </html>""" | |
| f.write(html) | |
| finally: | |
| f.close() | |
| if __name__ == "__main__": | |
| findFile = "docker-compose.yml" | |
| findText = "theasker.ovh" | |
| htmlFile = "/home/ubuntu/docker/nginx/data/html/html/index.html" | |
| dir = '/home/ubuntu/docker/' | |
| sites=[] | |
| find_files(dir, findFile, findText) | |
| create_file(htmlFile,sites) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment