-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* upload initial setup * provide text post method * add db init * use precommit, create db model * commit to db
- Loading branch information
Showing
13 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
max-line-length = 90 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# pre-commit hooks for the Python project | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 24.4.2 | ||
hooks: | ||
- id: black | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: 7.0.0 | ||
hooks: | ||
- id: flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
flask | ||
flask-sqlalchemy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from website import create_app | ||
|
||
app = create_app() | ||
|
||
if __name__ == "__main__": | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from flask import Flask | ||
from flask_sqlalchemy import SQLAlchemy | ||
from os import path | ||
|
||
db = SQLAlchemy() | ||
DB_NAME = "email-donations.db" | ||
|
||
|
||
def create_app(): | ||
app = Flask(__name__) | ||
app.config["SECRET_KEY"] = "wrgeerngh npitgn rion" | ||
app.config["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{DB_NAME}" | ||
db.init_app(app) | ||
|
||
from .views import views | ||
from .donate import donate | ||
from .about import about | ||
|
||
app.register_blueprint(views, url_prefix="/") | ||
app.register_blueprint(donate, url_prefix="/") | ||
app.register_blueprint(about, url_prefix="/") | ||
|
||
from .models import RawData, ProcessedData # noqa | ||
|
||
with app.app_context(): | ||
db.create_all() | ||
|
||
return app | ||
|
||
|
||
def create_database(app): | ||
if not path.exists("website/" + DB_NAME): | ||
db.create_all(app=app) | ||
print("Created Database!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from flask import Blueprint, render_template | ||
|
||
about = Blueprint("about", __name__) | ||
|
||
|
||
@about.route("/aboutus") | ||
def aboutus(): | ||
return render_template("about.html") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from flask import Blueprint, render_template, request, flash, redirect, url_for | ||
from werkzeug.security import generate_password_hash | ||
from .models import RawData | ||
from . import db | ||
|
||
donate = Blueprint("donate", __name__) | ||
|
||
|
||
@donate.route("/donation", methods=["GET", "POST"]) | ||
def donation(): | ||
if request.method == "GET": | ||
return render_template("donate.html") | ||
elif request.method == "POST": | ||
text = request.form.get("text") | ||
# make sure this is not empty | ||
if not text: | ||
flash("Please provide text input", category="error") | ||
else: | ||
# at the moment we are generating the hash checksum for the raw text | ||
new_submission = RawData( | ||
donation=text, | ||
checksum=generate_password_hash(text, method="pbkdf2:sha256"), | ||
) | ||
# add to db | ||
db.session.add(new_submission) | ||
# make commit to db | ||
db.session.commit() | ||
flash("Text input received", category="success") | ||
# redirect to homepage | ||
return redirect(url_for("views.home")) | ||
|
||
return render_template("donate.html") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from . import db | ||
|
||
# import hashlib | ||
from sqlalchemy.sql import func | ||
|
||
|
||
# the raw data model | ||
class RawData(db.Model): | ||
# the submission id | ||
id = db.Column(db.Integer, primary_key=True) | ||
# should this be the donated data as zip? | ||
donation = db.Column(db.String(10000), nullable=False) | ||
# the hash checksum of the donation zip file, for example SHA-256 | ||
# could also be SHA-3 | ||
# Compute SHA-256 hash | ||
# sha256_hash = hashlib.sha256(data).hexdigest() | ||
checksum = db.Column(db.String(100), nullable=False) | ||
# Now the metadata | ||
# the date of the donation | ||
date = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) | ||
# the email of the donor | ||
email = db.Column(db.String(100), nullable=True) | ||
# the age group of the donor in categories | ||
age = db.Column(db.Integer, nullable=True) | ||
# the region of the donor in categories | ||
region = db.Column(db.String(100), nullable=True) | ||
# the gender of the donor in categories | ||
gender = db.Column(db.Integer, nullable=True) | ||
# if the emails are in the mother tongue of the donor | ||
mother_tongue = db.Column(db.Integer, nullable=True) | ||
# the type of emails: formal, informal, etc. as categories | ||
email_type = db.Column(db.Integer, nullable=True) | ||
# set up the relationship with the processed data | ||
# emails = db.relationship("ProcessedData") | ||
|
||
|
||
class ProcessedData(db.Model): | ||
# the submission id | ||
id = db.Column(db.Integer, primary_key=True) | ||
# the raw email text | ||
raw_email = db.Column(db.String(100000), nullable=False) | ||
# the processed pseudonymized email text | ||
processed_email = db.Column(db.String(100000), nullable=False) | ||
# the date of the processing | ||
date = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) | ||
# the language of the email | ||
language = db.Column(db.String(10), nullable=False) | ||
# the original donation id, one to many relationship | ||
# donation_id = db.Column(db.Integer, db.ForeignKey("rawdata.id"), nullable=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% extends "base.html" %} {% block title%}About{% endblock %} {% block content %} | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link | ||
rel="stylesheet" | ||
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" | ||
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" | ||
crossorigin="anonymous" | ||
/> | ||
<link | ||
rel="stylesheet" | ||
href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" | ||
crossorigin="anonymous" | ||
/> | ||
<title>{% block title %}Home{% endblock %}</title> | ||
</head> | ||
<body> | ||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> | ||
<button | ||
class="navbar-toggler" | ||
type="button" | ||
data-toggle="collapse" | ||
data-target="#navbar" | ||
> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
<div class="collapse navbar-collapse" id="navbar"> | ||
<div class="navbar-nav"> | ||
<a class="nav-item nav-link" id="home" href="/">Home</a> | ||
<a class="nav-item nav-link" id="about" href="/aboutus">About</a> | ||
<a class="nav-item nav-link" id="donate" href="/donation">Donate</a> | ||
</div> | ||
</div> | ||
</nav> | ||
|
||
{% with messages = get_flashed_messages(with_categories=true) %} | ||
{% if messages %} | ||
{% for category, message in messages %} | ||
<div class="alert alert-{{ category }} alter-dismissable fade show" role=alert> | ||
{{ message }} | ||
<buttong type="button" class="close" data-dismiss="alert"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
{% endfor %} | ||
{% endif %} | ||
|
||
{% endwith %} | ||
{% block content %}{% endblock %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends "base.html" %} {% block title%}Donate{% endblock %} {% block content %} | ||
<form method="POST"> | ||
<h3 align="center">Donate</h3> | ||
<div class="form-group"> | ||
<label for="text">Text</label> | ||
<input | ||
type="text" | ||
class="form-control" | ||
id="text" | ||
name="text" | ||
placeholder="Enter text" | ||
/> | ||
</div> | ||
<br /> | ||
<button type="submit" class="btn btn-primary">Submit</button> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% extends "base.html" %} | ||
content %} | ||
{% block content %} | ||
<div class="container"> | ||
<h1>Welcome to the Home Page</h1> | ||
<p> | ||
This is the home page of our website. You can learn more about us by | ||
visiting the <a href="/about">About</a> page. | ||
</p> | ||
<p> | ||
{{ message }} | ||
</p> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from flask import Blueprint, render_template | ||
|
||
views = Blueprint("views", __name__) | ||
|
||
|
||
@views.route("/") | ||
def home(): | ||
return render_template("home.html", message="Hello, world!") |