From 8ff302166a9db213ef31e0739ef459389ee32f35 Mon Sep 17 00:00:00 2001 From: hornet Date: Fri, 11 Oct 2024 00:04:02 +0500 Subject: [PATCH] redirecting and rendering board pages --- README.md | 29 ++++++++++++++++++++++++++++- app.py | 36 +++++++++++++++++++++++++++++++++--- mongo.py | 11 +++++++++++ templates/board.html | 24 +++++++++++++++++++----- templates/index.html | 7 ++++--- 5 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 mongo.py diff --git a/README.md b/README.md index e45b46c..58adaa4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,30 @@ # wirechan -imageboard written in python(flask) \ No newline at end of file +imageboard written in python(flask) + +# overview + +wirechan is an anonymous(optional registration) imageboard written in Flask framework using MongoDB as a database. It's designed to be used +as a way of communication for various topics without the fear of being recogniszed, if the user wishes to remain unknown. + +# installation + +1. Clone the repository: +``` +git clone https://git.lainlounge.xyz/hornet/wirechan +``` + +2. Create and activate virtual environment: +``` +python3 -m venv venv +``` + +3. Install the dependencies: +``` +python3 -m pip install -r requirements.txt +``` + +4. Initialize the MongoDB server: +``` +mongo +``` \ No newline at end of file diff --git a/app.py b/app.py index 5c8a0d3..801322e 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,17 @@ -from flask import Flask, url_for, redirect, render_template +from flask import Flask, url_for, redirect, render_template, request +from pymongo import MongoClient +from datetime import datetime +from bson.objectid import ObjectId app = Flask(__name__) +#initialize the database +client = MongoClient('localhost', 27017) +db = client.flask_db +posts_collection = db.posts_collection + + +#app routes @app.route('/', methods=['GET']) def index(): return render_template('index.html') @@ -15,11 +25,31 @@ def board(board_name): {'name': 'v', 'display_name': '/v/ - video games'}, {'name': 'w', 'display_name': '/w/ - wallpapers'}, {'name': 'x', 'display_name': '/x/ - paranormal'}, - {'name': 'z', 'display_name': '/z/ - test'}, + {'name': 't', 'display_name': '/t/ - test'}, {'name': 's', 'display_name': '/s/ - soyjaks'}, {'name': 'pol', 'display_name': '/pol/ - politically incorrect'} ] - return render_template('board.html', title=board_name, header=board_name, links=links) + #global posts + #posts = posts_collection.find({'board_name': board_name}).sort('timestamp', -1) + display_name = next((link['display_name'] for link in links if link['name'] == board_name), board_name) + return render_template('board.html', title=board_name, header=display_name, links=links) + +@app.route('/post', methods=['POST']) +def post(): + board_name = request.form['board_name'] + content = request.form['content'] + image = request.files['image'] + timestamp = datetime.now() + + #insert the post into MongoDB + posts.insert_one({ + 'board_name': board_name, + 'content': content, + 'image': image.read(), + 'timestamp': timestamp + }) + + return redirect(url_for('board', board_name=board_name)) if __name__ == '__main__': diff --git a/mongo.py b/mongo.py new file mode 100644 index 0000000..d0642e5 --- /dev/null +++ b/mongo.py @@ -0,0 +1,11 @@ +from flask import Flask, url_for, redirect, render_template, request +from pymongo import MongoClient +from datetime import datetime +from bson.objectid import ObjectId + +app = Flask(__name__) + +#initialize the database +client = MongoClient('localhost', 27017) +db = client.flask_db +posts = db.posts diff --git a/templates/board.html b/templates/board.html index ec475ca..5ae0cfb 100644 --- a/templates/board.html +++ b/templates/board.html @@ -1,18 +1,32 @@ - + {{ title }} - + -{% extends "index.html" %} - {% block content %} {% endblock %} diff --git a/templates/index.html b/templates/index.html index 1797d30..e618392 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,4 +1,3 @@ - wirechan @@ -17,12 +16,14 @@ /v/ - video games /w/ - wallpapers /x/ - paranormal - /z/ - test + /t/ - test /s/ - soyjaks /pol/ - politically incorrect - +
lainlounge.xyz - copyleft all wrongs released
+ {% block content %} + {% endblock %} \ No newline at end of file