Script generador de sitios para servidores tildes
También puede servir para otros lugares donde busques minimalismo o mínimo consumo de recursos.
En este breve script podés construirte, desde la terminal, un pequeño sitio (index.html, bah). Podés seleccionar entre 3 temas posibles, escribis en el editor de textos favorito (en mi caso Neovim, pero cambialo en el script cuando abrís):
#Creador de pequeños sitios presenciales de una sola página, para tildes
#Por HI7903b
import os
import subprocess
from datetime import datetime
anio = datetime.now().year
terminal_tranquila = """
<style>
body {
background: #f4f1ea;
color: #2f2f2f;
font-family: Arial, sans-serif;
max-width: 700px;
margin: auto;
padding: 40px 20px;
line-height: 1.7;
}
h1 {
color: #7c8c6c;
border-bottom: 2px solid #b7a58a;
padding-bottom: 10px;
}
.descripcion {
margin-top: 20px;
font-size: 1.1em;
}
footer {
margin-top: 60px;
padding-top: 20px;
border-top: 1px solid #444;
font-size: 0.9em;
opacity: 0.8;
text-align: center;
}
a {
color: #7c8c6c;
}
a:hover {
opacity: 0.8;
}
img {
max-width: 100%;
height: auto;
}
</style>
"""
noches_de_synth = """
<style>
body {
background: #1e1f29;
color: #d9e0ee;
font-family: Arial, sans-serif;
max-width: 700px;
margin: auto;
padding: 40px 20px;
line-height: 1.7;
}
h1 {
color: #89b4fa;
border-bottom: 2px solid #f5c2e7;
padding-bottom: 10px;
}
.descripcion {
margin-top: 20px;
font-size: 1.1em;
}
footer {
margin-top: 60px;
padding-top: 20px;
border-top: 1px solid #444;
font-size: 0.9em;
opacity: 0.8;
text-align: center;
}
a {
color: #89b4fa;
}
a:hover {
opacity: 0.8;
}
img {
max-width: 100%;
height: auto;
}
</style>
"""
cuaderno_indie = """
<style>
body {
background: #fffaf3;
color: #3a3a3a;
font-family: Arial, sans-serif;
max-width: 700px;
margin: auto;
padding: 40px 20px;
line-height: 1.7;
}
h1 {
color: #d4a373;
border-bottom: 2px solid #ccd5ae;
padding-bottom: 10px;
}
.descripcion {
margin-top: 20px;
font-size: 1.1em;
}
footer {
margin-top: 60px;
padding-top: 20px;
border-top: 1px solid #444;
font-size: 0.9em;
opacity: 0.8;
text-align: center;
}
a {
color: #d4a373;
}
a:hover {
opacity: 0.8;
}
img {
max-width: 100%;
height: auto;
}
</style>
"""
temas = {
"1": terminal_tranquila,
"2": noches_de_synth,
"3": cuaderno_indie
}
eleccion = input("""Elegí un tema para el sitio:
"1": terminal_tranquila,
"2": noches_de_synth,
"3": cuaderno_indie
Si ponés otra cosa, en el HTML va salir "NONE"
""")
css = temas.get(eleccion)
#print (f"El tema seleccionado es el {css}")
titulo = input ("Nombre del sitio: ")
subtitulo = input ("Algún subtitulo: ")
#Vamos a escribir el contenido en un archivo, guardarlo y que luego lo capture
ruta = os.getcwd()
print (ruta)
ruta_archivo_nuevo = os.path.join(ruta, "texto_contenido.txt")
print (ruta_archivo_nuevo)
# Abrir el archivo en nvim
subprocess.run(["nvim", ruta_archivo_nuevo])
with open (ruta_archivo_nuevo, "r") as archivo_texto:
texto = archivo_texto.read()
#Escribir el html
with open ("index.html", 'w') as archivo:
archivo.write(f"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{titulo}</title>
{css}
</head>
<body>
<h1>{titulo}</h1>
<br>
{subtitulo}
<p>
{texto}
</p>
<footer>
Copyleft {anio} por {titulo} <br>
Esta página fue creada artesanalmente con Python y Neovim.
<br>
<a href="generador.py">Descargar el generador</a>
</footer>
</body>
</html>
""")
print ("Todo creado. ¡A disfrutar!")