feat: Add site edit
This commit is contained in:
34
sites/db.py
34
sites/db.py
@@ -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]
|
||||
@@ -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>')
|
||||
|
||||
Reference in New Issue
Block a user