commit a0357ceee0d4b6c6d3ecd5609b99821d030b19d9 Author: Kate Date: Sat Nov 14 18:50:11 2020 +0000 Initial Commit diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..1d0a061 --- /dev/null +++ b/Pipfile @@ -0,0 +1,13 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +flask = "*" +pymongo = "*" + +[dev-packages] + +[requires] +python_version = "3.9" diff --git a/db.py b/db.py new file mode 100644 index 0000000..889df7d --- /dev/null +++ b/db.py @@ -0,0 +1,21 @@ +import pymongo +connection = pymongo.MongoClient() +db = connection.smash +qdb = db.quotes +adb = db.accounts + +def get_random_quote(): + x = dict( qdb.aggregate([ + { "$match": { "hidden": False } }, + { "$sample": { "size": 1 } } + ]) ) + print(x) + return(x) + + +def add_quote(quote, tags, author): + qdb.insert_one({ + "quote": quote, + "tags": tags, + "author": author + }) diff --git a/main.py b/main.py new file mode 100644 index 0000000..a2c289b --- /dev/null +++ b/main.py @@ -0,0 +1,49 @@ +import datetime, random, json, pymongo +from flask import Flask, render_template, Markup, request, abort, session, g +import db as dblib +#from smash import app, conf + +app = Flask(__name__) + +#Connect to and define db +connection = pymongo.MongoClient() +db = connection.testdb +qdb = db.quotes + +def timestamp(): + return datetime.datetime.now().strftime("%H:%M:%S %d/%m/%y") + +def message(level, msg): + return render_template( + "message.html", + alertclass=level, + message=msg, + title="Message" + ) + +@app.route('/') +def index(): + news = "No quotes yet!" + #welcome = conf.config['MOTD'] + welcome = "MOTD" + print(qdb.find().count()) + qCount = qdb.find({"hidden": False}).count() + print(type(qCount)) + news = "Home of " + str(qCount) + " dumb quotes!" + if qCount > 0: + rand_quote = dblib.get_random_quote() + quote_text = Markup.escape(rand_quote['quote'])#.replace('\n', '
') + news = quote_text + permalink = str(rand_quote['id']) + + return render_template( + "index.html", + title="Quotes", + welcometext=welcome, + newstext=news, + permalink=permalink + ) + + +if __name__ == "__main__": + app.run(host="0.0.0.0", debug=True) diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..b9bc936 --- /dev/null +++ b/static/style.css @@ -0,0 +1,3 @@ +pre{ + +} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..e0023d2 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,15 @@ +{% extends "layout.html" %} +{% block customhead %} + {{ title }} +{% endblock %} +{% block nav_home %}active{% endblock %} +{% block content %} +
+
+

{{ title }}

+

{{ welcometext }}

+
{{ newstext|safe }}
+ Permalink +
+
+{% endblock %} diff --git a/templates/latest.html b/templates/latest.html new file mode 100644 index 0000000..e69de29 diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..8353c39 --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,40 @@ + + + + + + + {% block customhead %} + {% endblock %} + + + + + {% block content %} + {% endblock %} + + + \ No newline at end of file