]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/commitdiff
Reformat with autopep8
authorMichal Sojka <michal.sojka@cvut.cz>
Fri, 10 Aug 2018 09:04:21 +0000 (11:04 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Fri, 10 Aug 2018 09:04:21 +0000 (11:04 +0200)
app.py

diff --git a/app.py b/app.py
index e8d7154aed61b63cd9007ff12c76095e9f472e59..083114cc966db21df5086c2f24257a120b79a5c7 100644 (file)
--- a/app.py
+++ b/app.py
@@ -16,13 +16,15 @@ app = Flask(__name__)
 CORS(app, supports_credentials=True)
 app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
 
+
 @app.route('/')
 def hello():
     if "uid" in session:
-        uid = session["uid"];
+        uid = session["uid"]
         return render_template('hello.html', name=db.get_name(uid))
     return render_template('hello.html')
 
+
 @app.route('/login', methods=["POST"])
 @app.route('/login/<uid>')
 def login(uid=None):
@@ -30,34 +32,38 @@ def login(uid=None):
         uid = request.data.decode("utf-8")
     if uid is not None:
         db.add_user(uid)
-        session["uid"] = uid;
+        session["uid"] = uid
     return redirect(url_for('user'))
 
+
 @app.route('/logout')
 def logout():
     session.pop('uid', None)
     return redirect(url_for('user'))
 
+
 @app.route('/user')
 def user():
     if "uid" in session:
-        uid = session["uid"];
+        uid = session["uid"]
         return render_template('user.html',
-                name=db.get_name(uid),
-                flavors=db.flavors(),
-                count=db.coffee_count(uid, 0),
-                stamp=time.time()
-                )
+                               name=db.get_name(uid),
+                               flavors=db.flavors(),
+                               count=db.coffee_count(uid, 0),
+                               stamp=time.time()
+                               )
     return render_template('user.html')
 
+
 @app.route('/user/rename')
 def user_rename():
     name = request.args.get("name")
     if name and "uid" in session:
-        uid = session["uid"];
+        uid = session["uid"]
         db.name_user(uid, name)
     return redirect(url_for('user'))
 
+
 @app.route("/coffee/graph_flavors")
 def coffee_graph_flavors():
     b = BytesIO()
@@ -66,7 +72,7 @@ def coffee_graph_flavors():
         flavors, counts = zip(*db.coffee_flavors(uid))
     else:
         flavors, counts = zip(*db.coffee_flavors())
-    fig = plt.figure(figsize=(3,3))
+    fig = plt.figure(figsize=(3, 3))
     ax = fig.add_subplot(111)
     ax.set_aspect(1)
     ax.pie(counts)
@@ -76,6 +82,7 @@ def coffee_graph_flavors():
     b.seek(0)
     return send_file(b, mimetype="image/svg+xml")
 
+
 @app.route("/coffee/graph_history")
 def coffee_graph_history():
     b = BytesIO()
@@ -90,34 +97,34 @@ def coffee_graph_history():
         flavors = tuple()
     else:
         days, counts, flavors = zip(*hist)
-    fig = plt.figure(figsize=(4,3))
+    fig = plt.figure(figsize=(4, 3))
     ax = fig.add_subplot(111)
 
-    list_flavor=sorted(db.flavors())
-    l=[{} for i in range(len(list_flavor))]
+    list_flavor = sorted(db.flavors())
+    l = [{} for i in range(len(list_flavor))]
     for ll in l:
         for d in days:
             ll[d] = 0
 
     for(d, c, f) in zip(days, counts, flavors):
-       if f is None:
-           continue
-       what_f = 0
-       for i in range(len(list_flavor)):
-           if f == list_flavor[i]:
-              what_f = i;
-              break
-       l[what_f][d] += c
-
-    z=list(0 for i in range(len(l[0])))
+        if f is None:
+            continue
+        what_f = 0
+        for i in range(len(list_flavor)):
+            if f == list_flavor[i]:
+                what_f = i
+                break
+        l[what_f][d] += c
+
+    z = list(0 for i in range(len(l[0])))
     for flavor in range(len(list_flavor)):
         sortedlist = [(k, l[flavor][k]) for k in sorted(l[flavor])]
-        x=[i[0] for i in sortedlist]
-        y=[i[1] for i in sortedlist]
-        ax.bar(range(len(x)),y,bottom=z)
-        z=[sum(i) for i in zip(y, z)]
+        x = [i[0] for i in sortedlist]
+        y = [i[1] for i in sortedlist]
+        ax.bar(range(len(x)), y, bottom=z)
+        z = [sum(i) for i in zip(y, z)]
 
-    days=set(days)
+    days = set(days)
     xdays = [i.strftime("%a") for i in [
         date.today() - timedelta(j - 1) for j in
         range(len(days), 0, -1)]]
@@ -131,6 +138,7 @@ def coffee_graph_history():
     plt.close(fig)
     return send_file(b, mimetype="image/svg+xml")
 
+
 @app.route("/coffee/add", methods=["POST"])
 def coffee_add():
     if request.method == "POST":
@@ -139,18 +147,21 @@ def coffee_add():
             db.add_coffee(session["uid"], json["flavor"], json["time"])
     return redirect(url_for('user'))
 
+
 @app.route("/coffee/count")
 def coffee_count():
     start = request.args.get("start")
     stop = request.args.get("stop")
     return str(db.coffee_count(session.get("uid"), start, stop))
 
+
 @app.route('/js')
 def js():
     response = make_response(render_template('main.js'))
     response.headers['Content-Type'] = "text/javascript"
     return response
 
+
 @app.route("/log", methods=["POST"])
 def log():
     if request.method == "POST":