diff --git a/Dockerfile b/Dockerfile index aca0183..831c15a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM debian RUN apt-get update ; apt-get -y upgrade ; \ - apt-get -y install python3 python3-flask python3-flask-sqlalchemy python3-flask-httpauth python3-pymysql python3-requests python3-bs4 phantomjs ; \ + apt-get -y install python3 python3-flask python3-flask-sqlalchemy python3-flask-httpauth python3-flaskext.wtf python3-pymysql python3-requests python3-bs4 phantomjs ; \ rm -rf /var/lib/apt/lists/* diff --git a/app.py b/app.py index 0f8d971..e4aa8fa 100644 --- a/app.py +++ b/app.py @@ -1,29 +1,9 @@ from os import environ -from sys import modules -import pymysql -from flask import Flask -from flask_httpauth import HTTPBasicAuth -from flask_sqlalchemy import SQLAlchemy -from werkzeug.middleware.proxy_fix import ProxyFix +from flask import redirect, render_template, url_for -modules["MySQLdb"] = pymysql - -# init DB and migration -db_user = environ.get('MYSQL_USER') -db_password = environ.get('MYSQL_PASSWORD') -db_name = environ.get('MYSQL_DATABASE') -db_host = environ.get('MYSQL_HOST') -if not db_host or not db_user or not db_password or not db_name: - print('Missing connection environment variables') - exit() - -app = Flask(__name__) -app.wsgi_app = ProxyFix(app.wsgi_app) -app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://%s:%s@%s/%s' % (db_user, db_password, db_host, db_name) -app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True -auth = HTTPBasicAuth() -db = SQLAlchemy(app) +from config import app, auth +from models import SearchForm @auth.verify_password @@ -34,8 +14,16 @@ def verify_password(username, password): @app.route('/') -def hello_world(): - return 'Hello World !' +def home(): + form = SearchForm() + if form.validate_on_submit(): + return redirect(url_for('search', q=form.q)) + return render_template('home.html', form=form) + + +@app.route('/search') +def search(): + return 'Hello!' if __name__ == '__main__': diff --git a/config.py b/config.py new file mode 100644 index 0000000..94fbabd --- /dev/null +++ b/config.py @@ -0,0 +1,25 @@ +from os import environ, urandom +from sys import modules + +import pymysql +from flask import Flask +from flask_httpauth import HTTPBasicAuth +from flask_sqlalchemy import SQLAlchemy + +modules["MySQLdb"] = pymysql + +# init DB and migration +db_user = environ.get('MYSQL_USER') +db_password = environ.get('MYSQL_PASSWORD') +db_name = environ.get('MYSQL_DATABASE') +db_host = environ.get('MYSQL_HOST') +if not db_host or not db_user or not db_password or not db_name: + print('Missing connection environment variables') + exit() + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://%s:%s@%s/%s' % (db_user, db_password, db_host, db_name) +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True +app.secret_key = urandom(24).hex() +auth = HTTPBasicAuth() +db = SQLAlchemy(app) diff --git a/models.py b/models.py index 06feaa0..29b8852 100644 --- a/models.py +++ b/models.py @@ -1,4 +1,8 @@ -from app import db +from flask_wtf import FlaskForm +from wtforms.fields.html5 import SearchField +from wtforms.validators import DataRequired + +from config import db class AnimeFolder(db.Model): @@ -24,3 +28,7 @@ class AnimeLink(db.Model): vf = db.Column(db.Boolean, nullable=False) title_id = db.Column(db.Integer, db.ForeignKey('title.id')) title = db.relationship('AnimeTitle', back_populates="links") + + +class SearchForm(FlaskForm): + q = SearchField('search', validators=[DataRequired]) diff --git a/requirements.txt b/requirements.txt index c6a25ea..3c26d31 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ Flask==1.0.2 Flask-SQLAlchemy==2.1 Flask-HTTPAuth==3.2.4 +Flask-WTF===0.14.2 PyMySQL==0.9.3 requests==2.21.0 beautifulsoup4==4.7.1 diff --git a/static/favicons/favicon.ico b/static/favicons/favicon.ico new file mode 100644 index 0000000..48d8da0 Binary files /dev/null and b/static/favicons/favicon.ico differ diff --git a/templates/home.html b/templates/home.html new file mode 100644 index 0000000..48a21f7 --- /dev/null +++ b/templates/home.html @@ -0,0 +1,3 @@ +{% extends "layout.html" %} +{% block title %}Animes torrents search engine{% endblock %} +{% block body %}{% endblock %} diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..d87621d --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,45 @@ + + +
+ + + + +