1
0
Fork 0
forked from hornet/wirechan

redirecting and rendering board pages

This commit is contained in:
hornet 2024-10-11 00:04:02 +05:00
parent e25a4c2288
commit 8ff302166a
5 changed files with 95 additions and 12 deletions

View file

@ -1,3 +1,30 @@
# wirechan # wirechan
imageboard written in python(flask) 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
```

36
app.py
View file

@ -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__) 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']) @app.route('/', methods=['GET'])
def index(): def index():
return render_template('index.html') return render_template('index.html')
@ -15,11 +25,31 @@ def board(board_name):
{'name': 'v', 'display_name': '/v/ - video games'}, {'name': 'v', 'display_name': '/v/ - video games'},
{'name': 'w', 'display_name': '/w/ - wallpapers'}, {'name': 'w', 'display_name': '/w/ - wallpapers'},
{'name': 'x', 'display_name': '/x/ - paranormal'}, {'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': 's', 'display_name': '/s/ - soyjaks'},
{'name': 'pol', 'display_name': '/pol/ - politically incorrect'} {'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__': if __name__ == '__main__':

11
mongo.py Normal file
View file

@ -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

View file

@ -1,18 +1,32 @@
<!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title> <title>{{ title }}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
</head> </head>
<body> <body>
{% extends "index.html" %}
{% block content %} {% block content %}
<div class="link-container"> <div class="link-container">
<h2>{{ header }}</h2> <h2>{{ header }}</h2>
<p>{{ content }}</p> <form action="{{ url_for('post') }}" method="post" enctype="multipart/form-data">
<input type="hidden" name="board_name" value="{{ header }}">
<textarea name="content" rows="4" cols="50" placeholder="Write your post here..."></textarea>
<input type="file" name="image">
<button type="submit">Post</button>
</form>
<div class="posts">
{% for post in posts %}
<div class="post">
<p>{{ post.content }}</p>
{% if post.image %}
<img src="{{ url_for('image', post_id=post._id) }}" alt="Post Image">
{% endif %}
<small>{{ post.timestamp }}</small>
</div>
{% endfor %}
</div>
</div> </div>
{% endblock %} {% endblock %}
</body> </body>

View file

@ -1,4 +1,3 @@
<!DOCTYPE html>
<html> <html>
<head> <head>
<title>wirechan</title> <title>wirechan</title>
@ -17,12 +16,14 @@
<a href="{{ url_for('board', board_name='v') }}">/v/ - video games</a> <a href="{{ url_for('board', board_name='v') }}">/v/ - video games</a>
<a href="{{ url_for('board', board_name='w') }}">/w/ - wallpapers</a> <a href="{{ url_for('board', board_name='w') }}">/w/ - wallpapers</a>
<a href="{{ url_for('board', board_name='x') }}">/x/ - paranormal</a> <a href="{{ url_for('board', board_name='x') }}">/x/ - paranormal</a>
<a href="{{ url_for('board', board_name='z') }}">/z/ - test</a> <a href="{{ url_for('board', board_name='t') }}">/t/ - test</a>
<a href="{{ url_for('board', board_name='s') }}">/s/ - soyjaks</a> <a href="{{ url_for('board', board_name='s') }}">/s/ - soyjaks</a>
<a href="{{ url_for('board', board_name='pol') }}">/pol/ - politically incorrect</a> <a href="{{ url_for('board', board_name='pol') }}">/pol/ - politically incorrect</a>
</div> </div>
<div class="bottom"> <div class="bottom">
<a>lainlounge.xyz - copyleft all wrongs released</a> <a>lainlounge.xyz - copyleft all wrongs released</a>
</div> </div>
{% block content %}
{% endblock %}
</body> </body>
</html> </html>