commit 4ab1622c94901c8d502125d7c0be9e9bc5b4b984
parent 4fcada244343e327cd07306e83763d653d18f21c
Author: Shiimoe <SameulFrost@tuta.io>
Date:   Sun, 13 Sep 2020 18:46:51 +0100
ignore local comments
Diffstat:
3 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,3 +1,4 @@
 __pycache__/
 *.pyc
 desktop.ini
+comments.json+
\ No newline at end of file
diff --git a/comments.json b/comments.json
@@ -13,5 +13,10 @@
         "name": "shimo",
         "comment": "am I null?",
         "date": "2020-09-13 03:31"
+    },
+    {
+        "name": "ff",
+        "comment": "ff",
+        "date": "2020-09-13 18:46"
     }
 ] 
\ No newline at end of file
diff --git a/server.py b/server.py
@@ -8,15 +8,24 @@ import json
 COMMENT_FILE = "comments.json"
 DATE_FORMAT = "%Y-%m-%d %H:%M"
 
+def read_comments():
+    comments = None
+    try:
+        with open(COMMENT_FILE, 'r') as f:
+            comments = json.load(f)
+    except FileNotFoundError:
+        comments = []
+        
+    return comments
+    
+
 @app.route('/')
 def home():
     return send_from_directory('./', 'index.html')
 
 @app.route('/guestbook')
 def guestbook():
-    comments = None
-    with open(COMMENT_FILE, 'r') as f:
-        comments = json.load(f)
+    comments = read_comments()
     return render_template('guestbook.html', comments=reversed(comments))
 
 @app.route('/postcomment', methods=['POST'])
@@ -25,10 +34,7 @@ def postcomment():
     comment = request.form['comment']
     date = datetime.now()
 
-    comments = None
-    with open(COMMENT_FILE, 'r') as f:
-        comments = json.load(f)
-    
+    comments = read_comments()
     comments.append({
         'name': name,
         'comment': comment,