Initial Commit
This commit is contained in:
commit
a0357ceee0
7 changed files with 141 additions and 0 deletions
13
Pipfile
Normal file
13
Pipfile
Normal file
|
@ -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"
|
21
db.py
Normal file
21
db.py
Normal file
|
@ -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
|
||||
})
|
49
main.py
Normal file
49
main.py
Normal file
|
@ -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', '<br />')
|
||||
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)
|
3
static/style.css
Normal file
3
static/style.css
Normal file
|
@ -0,0 +1,3 @@
|
|||
pre{
|
||||
|
||||
}
|
15
templates/index.html
Normal file
15
templates/index.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
{% extends "layout.html" %}
|
||||
{% block customhead %}
|
||||
<title>{{ title }}</title>
|
||||
{% endblock %}
|
||||
{% block nav_home %}active{% endblock %}
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="jumbotron">
|
||||
<h1>{{ title }}</h1>
|
||||
<p>{{ welcometext }}</p>
|
||||
<pre>{{ newstext|safe }}</pre>
|
||||
<a href="{{permalink}}">Permalink</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
0
templates/latest.html
Normal file
0
templates/latest.html
Normal file
40
templates/layout.html
Normal file
40
templates/layout.html
Normal file
|
@ -0,0 +1,40 @@
|
|||
<html>
|
||||
<head>
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
|
||||
|
||||
<meta name="viewport" content="width=device-with,initial-scale=1.0">
|
||||
{% block customhead %}
|
||||
{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light mb-4">
|
||||
<a class="navbar-brand" href="#">Shit Haplo Says</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<li class="nav-item {% block nav_home %}{% endblock %}">
|
||||
<a class="nav-link" href="#">Home</a>
|
||||
</li>
|
||||
<li class="nav-item {% block nav_latest %}{% endblock %}">
|
||||
<a class="nav-link" href="#">Latest</a>
|
||||
</li>
|
||||
<li class="nav-item {% block nav_tags %}{% endblock %}">
|
||||
<a class="nav-link" href="#">Tags</a>
|
||||
</li>
|
||||
<li class="nav-item {% block nav_new_post %}{% endblock %}">
|
||||
<a class="nav-link" href="#">New Post</a>
|
||||
</li>
|
||||
<li class="nav-item {% block nav_administration_login %}{% endblock %}">
|
||||
<a class="nav-link" href="#">Administration Login</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Reference in a new issue