-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
127 lines (92 loc) · 2.76 KB
/
main.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import argparse
import os
import flask
from flask import Flask, render_template, jsonify, send_from_directory, url_for, request
from werkzeug.utils import secure_filename, redirect
from website import system
from website import articles
from flask.ext.uploads import *
app = Flask(__name__)
@app.route("/index")
@app.route("/")
def index():
return render_template("index.html")
@app.route("/contact", methods=["GET", "POST"])
def contact():
return render_template("contact.html")
@app.route("/_ram")
def get_ram():
response = {
"total": round(system.get_total_ram()),
"server": round(system.get_process_ram()),
"other": round(system.get_other_ram()),
}
return jsonify(response)
@app.route("/_cpu")
def get_cpu():
response = {
"percentage": [round(system.get_cpu())]
}
return jsonify(response)
# pages
@app.route("/stats")
def stats_page():
return render_template("stats.html")
@app.route("/projects")
def projects_page():
projects = [
{"title": "Useful Links", "url": "/articles/usefulLinks", "img": "static/img/tux.png", "text": "Collection of useful articles"},
{"title": "Website Development", "url": "/articles/websiteDevelopment1", "img": "static/img/html-tag.png", "text": "The history of this website"}
]
return render_template("projects.html", projects=projects)
@app.route("/articles")
def articles_page():
recentArticles = reversed(articles.get_published())
return render_template("articles.html", articles=recentArticles)
@app.route("/articles/<name>")
def getArticle(name):
info = articles.get_article_data_by_url(name)
html = articles.get_article_html(name)
related = []
try:
for article in info["related"]:
try:
related.append(articles.get_article_data_by_url(article))
except FileNotFoundError:
pass
except KeyError:
pass
if len(related) == 0:
related = None
print("Displaying {}".format(info))
return render_template("article.html", info=info, html=html, related=related)
@app.route("/search")
def getSearchResults():
return jsonify
@app.route("/woggles")
def woggles():
return render_template("woggles.html")
@app.route("/files/<path:path>")
def serve_file(path):
dir = os.path.join(os.getcwd(), "files")
print(dir)
return send_from_directory(dir, path)
@app.route("/upload", methods=["POST"])
def upload():
if request.method == "POST":
file = request.files["file"]
filename = secure_filename(file.filename)
path = os.path.join("files", filename)
if not os.path.isfile(path):
print(path, "doesn't exist")
file.save(path)
return redirect("/woggles")
else:
return "File with that name already exists", 418
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-d", dest="debug", type=bool)
args = parser.parse_args()
if args.debug:
app.debug = True
app.run()