Getting comments from DB
This commit is contained in:
parent
4edce022bd
commit
0b93d4da0a
Binary file not shown.
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"Comments": "Comments",
|
||||||
|
"DoReport": "Report",
|
||||||
|
"DoDelete": "Delete",
|
||||||
|
"DoReply": "Reply",
|
||||||
|
"Reply": "Reply",
|
||||||
|
"SecretKey": "Secret Key",
|
||||||
|
"Optional": "Optional",
|
||||||
|
"YourName": "Your Name",
|
||||||
|
"DoPost": "Post as New Comment"
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"Comments": "Commenti",
|
||||||
|
"DoReport": "Segnala",
|
||||||
|
"DoDelete": "Cancella",
|
||||||
|
"DoReply": "Rispondi",
|
||||||
|
"Reply": "Risposta",
|
||||||
|
"SecretKey": "Chiave Segreta",
|
||||||
|
"Optional": "Opzionale",
|
||||||
|
"YourName": "Il tuo Nome",
|
||||||
|
"DoPost": "Pubblica come Nuovo Commento"
|
||||||
|
}
|
|
@ -1,10 +1,13 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" href="Main.css">
|
<link rel="stylesheet" href="Main.css">
|
||||||
|
<style>
|
||||||
|
{Style}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form action="/Comments" method="get">
|
<form action="/Comments" method="POST">
|
||||||
{}
|
{Form}
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -1,6 +1,9 @@
|
||||||
<div id="PlainDiscussComment{ID}">
|
<div id="PlainDiscussComment{ID}">
|
||||||
<h5>{User}, {Date}, <a href="#PlainDiscussComment{ID}">#{ID}</a></h5>
|
<h5>{User}, {Date}, <a href="#PlainDiscussComment{ID}">#{ID}</a></h5>
|
||||||
<input type="checkbox" name="Select" value="{ID}">
|
<button type="submit" name="Report" value="{ID}">[Locale:DoReport]</button>
|
||||||
<button type="submit" name="Report" value="{ID}">Report</button>
|
<button type="submit" name="Delete" value="{ID}">[Locale:DoDelete]</button>
|
||||||
<button type="submit" name="Reply" value="{ID}">Reply to</button>
|
<button type="submit" name="Reply" value="{ID}">[Locale:DoReply]</button>
|
||||||
|
<p>
|
||||||
|
{Comment}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
<div>
|
<div>
|
||||||
<h3>Comments</h3>
|
<h3>Comments</h3>
|
||||||
<button type="submit" name="Action" value="Delete">Delete Selected</button>
|
|
||||||
<button type="submit" name="Action" value="Login">Admin Login</button>
|
<button type="submit" name="Action" value="Login">Admin Login</button>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<div>
|
<div>
|
||||||
<label>Secret Key (Optional):</label>
|
<label>[Locale:SecretKey] ([Locale:Optional]):</label>
|
||||||
<span><input type="password" name="SecretKey"></span>
|
<span><input type="password" name="SecretKey"></span>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
|
@ -15,12 +14,12 @@
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<div>
|
<div>
|
||||||
<label>Your Name:</label>
|
<label>[Locale:YourName]</label>
|
||||||
<span><input type="text" name="User"></span>
|
<span><input type="text" name="User"></span>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<div>
|
<div>
|
||||||
<label>Reply:</label>
|
<label>Reply:</label>
|
||||||
<button type="submit" name="Action" value="Post">Post as New Comment</button>
|
<button type="submit" name="Action" value="Post">[Locale:DoPost]</button>
|
||||||
<textarea name="Comment"></textarea>
|
<textarea name="Comment"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -8,9 +8,10 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import time
|
||||||
from ast import literal_eval
|
from ast import literal_eval
|
||||||
from flask import Flask, request, send_file
|
from flask import Flask, request, send_file
|
||||||
#from APIConfig import *
|
from pathlib import Path
|
||||||
|
|
||||||
App = Flask(__name__)
|
App = Flask(__name__)
|
||||||
|
|
||||||
|
@ -31,10 +32,20 @@ def WriteFile(p, c):
|
||||||
print("Error writing file {}".format(p))
|
print("Error writing file {}".format(p))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def GetLocales():
|
||||||
|
Locales = {}
|
||||||
|
for File in Path('Locale').rglob('*.json'):
|
||||||
|
File = str(File)
|
||||||
|
Lang = File[len('Locale/'):-len('.json')]
|
||||||
|
Locale = json.loads(ReadFile(File))
|
||||||
|
Locales.update({Lang:Locale})
|
||||||
|
return Locales
|
||||||
|
|
||||||
def GetConfig():
|
def GetConfig():
|
||||||
Config = {
|
Config = {
|
||||||
'Development': False,
|
'Development': False,
|
||||||
'Port': 8080}
|
'Port': 8080,
|
||||||
|
'Default Locale': 'en'}
|
||||||
File = ReadFile('Config.json')
|
File = ReadFile('Config.json')
|
||||||
if File:
|
if File:
|
||||||
File = json.loads(File)
|
File = json.loads(File)
|
||||||
|
@ -51,33 +62,56 @@ def InitDB():
|
||||||
def GetDB():
|
def GetDB():
|
||||||
return sqlite3.connect('Comments.db')
|
return sqlite3.connect('Comments.db')
|
||||||
|
|
||||||
def GetComments():
|
def GetComments(Site, Page):
|
||||||
return [0,0,0]
|
DB = GetDB()
|
||||||
|
|
||||||
|
SiteID = DB.cursor().execute('SELECT "ID" from "Sites" WHERE "PubKey" == "{}"'.format(Site))
|
||||||
|
PageID = DB.cursor().execute('SELECT "ID" FROM "Pages" WHERE "Site" == "{}" AND "Path" == "{}"'.format(SiteID, Page))
|
||||||
|
Comments = DB.cursor().execute('SELECT * FROM "Comments" WHERE "Page" == "{}"'.format(PageID))
|
||||||
|
|
||||||
|
DB.close()
|
||||||
|
return Comments
|
||||||
|
|
||||||
def PatchHTML(Data):
|
def PatchHTML(Data):
|
||||||
Base = ReadFile('Source/Main.html')
|
FormBase = ReadFile('Source/Form.Base.html')
|
||||||
FormMain = ReadFile('Source/Form.Main.html')
|
FormMain = ReadFile('Source/Form.Main.html')
|
||||||
FormComment = ReadFile('Source/Form.Comment.html')
|
FormComment = ReadFile('Source/Form.Comment.html')
|
||||||
|
|
||||||
|
if Data['Lang'] and Data['Lang'] in Locales:
|
||||||
|
Locale = Locales[Data['Lang']]
|
||||||
|
else:
|
||||||
|
Locale = Locales[Config['Default Locale']]
|
||||||
|
|
||||||
|
for String in Locale:
|
||||||
|
FormBase = FormBase.replace('[Locale:{}]'.format(String), Locale[String])
|
||||||
|
FormMain = FormMain.replace('[Locale:{}]'.format(String), Locale[String])
|
||||||
|
FormComment = FormComment.replace('[Locale:{}]'.format(String), Locale[String])
|
||||||
|
|
||||||
Comments = ''
|
Comments = ''
|
||||||
for i in GetComments():
|
for Comment in GetComments(Data['Site'], Data['Page']):
|
||||||
Comments += "\n<br><hr>\n" + FormComment.format(
|
Comments += "\n<hr>\n" + FormComment.format(
|
||||||
User="User",
|
User="User",
|
||||||
Date="Date",
|
Date="Date",
|
||||||
ID="ID")
|
ID="ID",
|
||||||
|
Comment="Comment")
|
||||||
|
|
||||||
return Base.format(FormMain + Comments)
|
return FormBase.format(Style='',Form=FormMain+Comments)
|
||||||
|
|
||||||
def Get(Req):
|
def Get(Req):
|
||||||
Data = {}
|
Data = {}
|
||||||
for i in ['Site','Page','User','CAPTCHA','Comment','SecretKey','Select','Action','Reply','Report']:
|
for i in ['Lang','StyleFile','Site','Page']:
|
||||||
Data.update({i:Req.args.get(i)})
|
Data.update({i:Req.args.get(i)})
|
||||||
print(Req.args.get(i))
|
|
||||||
return PatchHTML(Data)
|
return PatchHTML(Data)
|
||||||
|
|
||||||
def Post(Req):
|
def Post(Req):
|
||||||
Data = Req.get_json()
|
Data = {}
|
||||||
print(Data)
|
for i in ['Lang','StyleFile','Site','Page','User','CAPTCHA','Comment','SecretKey','Action','Reply','Report','Delete']:
|
||||||
|
Data.update({i:Req.args.get(i)})
|
||||||
|
return PatchHTML(Data)
|
||||||
|
|
||||||
|
@App.route('/Manage.html')
|
||||||
|
def SendManage():
|
||||||
|
return send_file('Manage.html')
|
||||||
|
|
||||||
@App.route('/Main.css')
|
@App.route('/Main.css')
|
||||||
def SendCSS():
|
def SendCSS():
|
||||||
|
@ -92,9 +126,12 @@ def Comments():
|
||||||
return Post(Req)
|
return Post(Req)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Locales = GetLocales()
|
||||||
Config = GetConfig()
|
Config = GetConfig()
|
||||||
|
|
||||||
DB = GetDB()
|
DB = GetDB()
|
||||||
InitDB()
|
InitDB()
|
||||||
|
DB.close()
|
||||||
|
|
||||||
if Config['Development']:
|
if Config['Development']:
|
||||||
App.run(host='0.0.0.0', port=Config['Port'], debug=True)
|
App.run(host='0.0.0.0', port=Config['Port'], debug=True)
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<iframe src="http://localhost:8080/Comments?Lang=it&Site=Test&Page=/index.html" width="100%" height="80%"></iframe>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue