-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·51 lines (41 loc) · 1.26 KB
/
Copy pathmain.py
File metadata and controls
executable file
·51 lines (41 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
from datetime import datetime
from flask import Flask, render_template, request, redirect, url_for
# app configuration
app = Flask(__name__)
app.debug = False
PORT = 8080
# rudimentary, hacky database
blogEntries = [] # this is a time-ordered MRU list of "entries"
# helper functions
def findUTCTimeString():
currDT = datetime.utcnow()
return currDT.strftime("%I:%M %p (UTC) %b %d, %Y")
def createEntry(author, title, text):
return {"author": author,
"title": title,
"text": text,
"datetime": findUTCTimeString()}
# routing
@app.route("/")
def homePage():
return render_template("index.html", entries = blogEntries)
@app.route("/about")
def aboutPage():
return render_template("about.html")
@app.route("/create")
def createPage():
return render_template("create.html")
@app.route("/newpost", methods=["POST"])
def newpost():
author = request.form["author"]
title = request.form["title"]
text = request.form["text"]
blogEntries.insert(0, createEntry(author, title, text))
return redirect(url_for("homePage"))
@app.route("/refreshEntries")
def refreshEntries():
return json.dumps(blogEntries)
# start the app if we're directly running this file
if __name__ == "__main__":
app.run(host = "0.0.0.0", port = PORT)