Commit 63bfed42 authored by Daniel Niecke's avatar Daniel Niecke

added key and db to server

parent c37d9c04
......@@ -113,3 +113,4 @@ venv.bak/
.mypy_cache/
/pw
/env
......@@ -47,4 +47,6 @@ CMD /usr/sbin/apache2ctl -D FOREGROUND
# docker rm -f news-reader
# docker run -d -e ENV=production -p 7777:80 --name news-reader news-reader
# docker build -t news-reader . ; docker rm -f news-reader ; docker run -d -e ENV=production -p 7777:80 --name news-reader news-reader
\ No newline at end of file
# docker build -t news-reader . ; docker rm -f news-reader ; docker run -d -e ENV=production -p 7777:80 --name news-reader news-reader
# docker run -d --name news-reader --net main_net --hostname news.niecke-it.de --env-file=env -e "LETSENCRYPT_HOST=news.niecke-it.de" -e "LETSENCRYPT_EMAIL=niecke@bwl.uni-kiel.de" -e "VIRTUAL_HOST=news.niecke-it.de" news-reader
\ No newline at end of file
Create DATABASE news;
CREATE TABLE news.user (
user_id INT AUTO_INCREMENT PRIMARY KEY,
`key` VARCHAR(256) UNIQUE,
kindle_url VARCHAR(256)
);
INSERT INTO news.user (`key`, kindle_url)
VALUES ('meinKey', 'd.p.a.niecke_e64c19@kindle.com');
\ No newline at end of file
......@@ -10,6 +10,8 @@
Require all granted
</Directory>
SetEnv MYSQL_PW ${MYSQL_PW}
SetEnv MYSQL_HOST ${MYSQL_HOST}
SetEnv ENV ${ENV}
# SSLEngine on
......
......@@ -11,5 +11,17 @@ application.secret_key = os.urandom(12)
if os.environ.get('ENV', '') == 'production':
logging.basicConfig(level=logging.INFO)
application.logger.info('Running in prod mode.')
application.config['DEBUG'] = False
application.config['TESTING'] = False
application.config['MYSQL_DATABASE_HOST'] = os.environ['MYSQL_HOST']
application.config['MYSQL_DATABASE_USER'] = 'news-reader'
application.config['MYSQL_DATABASE_PASSWORD'] = os.environ['MYSQL_PW']
else:
logging.basicConfig(level=logging.DEBUG)
\ No newline at end of file
logging.basicConfig(level=logging.DEBUG)
application.logger.info('Running in debug mode.')
application.config['DEBUG'] = True
application.config['TESTING'] = True
application.config['MYSQL_DATABASE_HOST'] = 'localhost'
application.config['MYSQL_DATABASE_USER'] = 'news-reader'
application.config['MYSQL_DATABASE_PASSWORD'] = os.environ['MYSQL_PW']
\ No newline at end of file
......@@ -34,14 +34,9 @@ def process_one_url(url):
outputFilename = "/tmp/tmp_{}.pdf".format(ran)
generate_pdf(pdf_string, outputFilename)
print("Done.")
send_to_kindle(article.title, outputFilename)
print("Done with {}".format(pdf_string.title()))
if os.path.exists(outputFilename):
os.remove(outputFilename)
return article.title, outputFilename
if __name__ == '__main__':
......
import smtplib
from select import select
from email import encoders
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
......@@ -6,11 +8,17 @@ import unidecode
import os
def send_to_kindle(title, filename):
def send_to_kindle(title, filename, key, engine):
print("Sending via mail...")
fromaddr = 'd.p.a.niecke@googlemail.com'
toaddr = 'd.p.a.niecke_e64c19@kindle.com'
# look up email to send to
connection = engine.connect()
# check if the user is a local one
toaddr = connection.execute("SELECT kindle_url FROM news.user WHERE key = '{}'".format(key))[0]
print(toaddr)
msg = MIMEMultipart()
msg['Subject'] = 'convert'
......
import os
from flask import Flask, render_template, flash, request
from wtforms import Form, TextField, validators
from sqlalchemy import create_engine
from send_to_kindle import send_to_kindle
from server import parse_compu_wo
# App config.
......@@ -12,7 +16,7 @@ app.config['SECRET_KEY'] = '7d441f27d441f27567d441f2b6176a'
class ReusableForm(Form):
url = TextField('Url:', validators=[validators.required()])
"""
@app.route("/", methods=['GET', 'POST'])
def save_url():
form = ReusableForm(request.form)
......@@ -34,12 +38,24 @@ def save_url():
flash('All the form fields are required. ')
return render_template('url_form.html', form=form)
"""
if app.config['DEBUG']:
engine = create_engine('sqlite:////azk/azk/test.db', echo=True)
else:
engine = create_engine('mysql://azk:{}@dbms.gruendung.bwl.uni-kiel.de/azk'.format(os.environ['MYSQL_PW']),
pool_pre_ping=True)
@app.route("/app", methods=['GET'])
@app.route("/app", methods=['POST'])
def save_from_app():
if request.args.get("url"):
parse_compu_wo.process_one_url(request.args.get("url"))
if request.form.get("url") and request.form.get("key"):
outputFilename, title= parse_compu_wo.process_one_url(request.form.get("url"))
send_to_kindle(title, outputFilename, request.form.get("key"), engine)
if os.path.exists(outputFilename):
os.remove(outputFilename)
return '', 200
else:
return '', 400
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment