feat: Add site edit
All checks were successful
Build Docker / Build Main Image (push) Successful in 20s
Build Docker / Build SLDs Image (push) Successful in 19s

This commit is contained in:
2023-11-08 20:43:33 +11:00
parent b02d8934c2
commit a0bb9dc032
6 changed files with 102 additions and 21 deletions

View File

@@ -12,28 +12,26 @@ dbargs = {
'database':os.getenv('DB_NAME')
}
def check_tables():
connection = mysql.connector.connect(**dbargs)
cursor = connection.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS site (
id INT(11) NOT NULL AUTO_INCREMENT,
domain VARCHAR(255) NOT NULL,
data VARCHAR(2048) NOT NULL,
PRIMARY KEY (id)
)
""")
cursor.close()
connection.close()
def get_site(domain):
def get_website_data(domain):
connection = mysql.connector.connect(**dbargs)
cursor = connection.cursor()
cursor.execute("""
SELECT * FROM site WHERE domain = %s
""", (domain,))
site = cursor.fetchall()
data = cursor.fetchall()
cursor.close()
connection.close()
return site
if data == []:
# Create new entry
connection = mysql.connector.connect(**dbargs)
cursor = connection.cursor()
cursor.execute("""
INSERT INTO site (domain, data)
VALUES (%s, %s)
""", (domain, ""))
connection.commit()
cursor.close()
connection.close()
return ""
return data[0][2]

View File

@@ -1,10 +1,11 @@
from flask import Flask, make_response, redirect, request, jsonify, render_template, send_from_directory
from flask import Flask, make_response, redirect, render_template_string, request, jsonify, render_template, send_from_directory
import os
import dotenv
import requests
import json
import schedule
import time
import db
app = Flask(__name__)
@@ -23,7 +24,13 @@ def error(message):
@app.route('/')
def index():
host = request.host
return jsonify({'success': True, 'message': host})
if len(host.split('.')) < 2:
return error('Invalid domain')
# Get website data
data = db.get_website_data(host)
# Render as HTML
return render_template_string(data)
@app.route('/<path:path>')