{{ post.content }}
+ {% if post.image %} +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 @@ - +
{{ content }}
+ +{{ post.content }}
+ {% if post.image %} +