2023-07-01 20:29:27 +10:00
|
|
|
from flask import Flask, render_template, request
|
|
|
|
from flask_assets import Bundle, Environment
|
2023-07-01 22:41:34 +10:00
|
|
|
from todo import todos
|
2023-07-12 01:50:29 +10:00
|
|
|
#from boards import board_list
|
2023-07-03 23:18:37 +10:00
|
|
|
from threads import threads_lists
|
2023-07-03 23:45:49 +10:00
|
|
|
from threads_with_posts import open_threads
|
2023-07-12 01:50:29 +10:00
|
|
|
from arango import ArangoClient
|
2023-07-01 20:29:27 +10:00
|
|
|
|
2023-07-03 23:02:48 +10:00
|
|
|
import socket
|
|
|
|
|
2023-07-01 20:29:27 +10:00
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
assets = Environment(app)
|
2023-07-03 23:28:41 +10:00
|
|
|
css = Bundle("src/*.css", output="dist/main.css")
|
2023-07-01 20:29:27 +10:00
|
|
|
|
|
|
|
# https://unpkg.com/htmx.org
|
|
|
|
js = Bundle("src/*.js", output="dist/main.js")
|
|
|
|
|
2023-07-03 23:28:41 +10:00
|
|
|
assets.register("css", css)
|
2023-07-01 20:29:27 +10:00
|
|
|
assets.register("js", js)
|
2023-07-03 23:28:41 +10:00
|
|
|
css.build()
|
2023-07-01 20:29:27 +10:00
|
|
|
js.build()
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-07-12 01:43:59 +10:00
|
|
|
|
2023-07-12 01:59:04 +10:00
|
|
|
arango_client = ArangoClient(hosts='https://arango.vdk2ch.ru')
|
2023-07-13 15:02:52 +10:00
|
|
|
db = arango_client.db('board1', username='root', password='stolendick527')
|
2023-07-12 01:43:59 +10:00
|
|
|
|
2023-07-12 01:50:29 +10:00
|
|
|
# предполагается что меняться список будет весьма редко, поэтому подхватываем при лишь при перезапуске
|
|
|
|
boards0 = db.collection('boards')
|
|
|
|
board_list = [ k['_key'] for k in boards0]
|
2023-07-12 01:43:59 +10:00
|
|
|
|
2023-07-03 22:46:40 +10:00
|
|
|
|
|
|
|
@app.route('/liveness')
|
|
|
|
def healthx():
|
|
|
|
return "<h1><center>Liveness check completed</center><h1>"
|
|
|
|
|
|
|
|
@app.route('/readiness')
|
|
|
|
def healthz():
|
|
|
|
return "<h1><center>Readiness check completed</center><h1>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-07-01 20:29:27 +10:00
|
|
|
@app.route("/")
|
2023-07-03 23:18:37 +10:00
|
|
|
def homepage():
|
2023-07-03 23:02:48 +10:00
|
|
|
docker_short_id = socket.gethostname()
|
|
|
|
return render_template("main-page.html", host_id=docker_short_id, boards=board_list)
|
2023-07-03 22:41:49 +10:00
|
|
|
|
2023-07-13 01:05:54 +10:00
|
|
|
|
2023-07-03 23:18:37 +10:00
|
|
|
@app.route("/boards/<board_id>")
|
|
|
|
def page_board(board_id):
|
2023-07-03 23:45:49 +10:00
|
|
|
|
|
|
|
b_threads = [ open_threads[thread_id] for thread_id in open_threads if thread_id in threads_lists[board_id]]
|
|
|
|
return render_template("board.html", board_id=board_id, boards=board_list, board_threads=b_threads)
|
2023-07-03 23:18:37 +10:00
|
|
|
|
|
|
|
|
2023-07-13 19:50:45 +10:00
|
|
|
|
|
|
|
@app.route("/db_posts")
|
|
|
|
def page_posts_from_db():
|
|
|
|
|
2023-07-13 19:57:40 +10:00
|
|
|
postos = db.collection('posts')
|
|
|
|
postos = [ p for p in postos]
|
2023-07-13 19:50:45 +10:00
|
|
|
|
|
|
|
return render_template("interactive-posts.html", postos=postos)
|
|
|
|
|
|
|
|
|
2023-07-13 15:12:58 +10:00
|
|
|
# @app.route('/post_my_post', method=['POST'])
|
|
|
|
# def post_a_post():
|
|
|
|
# pass
|
2023-07-13 01:05:54 +10:00
|
|
|
|
2023-07-13 15:12:58 +10:00
|
|
|
# @app.route('/post_my_file', method=['POST'])
|
|
|
|
# def post_a_file():
|
|
|
|
# pass
|
2023-07-13 01:05:54 +10:00
|
|
|
|
|
|
|
|
2023-07-03 22:58:08 +10:00
|
|
|
### stolen
|
2023-07-03 22:41:49 +10:00
|
|
|
@app.route("/todo")
|
|
|
|
def page_todo():
|
2023-07-01 20:29:27 +10:00
|
|
|
return render_template("page1.html")
|
|
|
|
|
|
|
|
|
2023-07-01 22:41:34 +10:00
|
|
|
@app.route("/search", methods=["POST"])
|
|
|
|
def search_todo():
|
|
|
|
search_term = request.form.get("search")
|
|
|
|
|
|
|
|
if not len(search_term):
|
|
|
|
return render_template("todo.html", todos=[])
|
|
|
|
|
|
|
|
res_todos = []
|
|
|
|
for todo in todos:
|
|
|
|
if search_term in todo["title"]:
|
|
|
|
res_todos.append(todo)
|
|
|
|
|
|
|
|
return render_template("todo.html", todos=res_todos)
|
2023-07-03 22:58:08 +10:00
|
|
|
### /stolen
|
2023-07-01 22:41:34 +10:00
|
|
|
|
|
|
|
|
2023-07-01 20:29:27 +10:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-07-02 00:46:17 +10:00
|
|
|
app.run(debug=True, host='0.0.0.0')
|