]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/commitdiff
Fix most of flake8 warnings
authorMichal Sojka <michal.sojka@cvut.cz>
Wed, 19 Aug 2020 13:09:24 +0000 (15:09 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Wed, 19 Aug 2020 22:28:02 +0000 (00:28 +0200)
I deliberately ignored warnings about long lines and a few more.

app.py
coffee_db.py

diff --git a/app.py b/app.py
index 14a26842d4faccf78c975f5e327bb3485f21f565..81bfbf137fca78e3c344a9b4092aa2c64e5a7d6b 100644 (file)
--- a/app.py
+++ b/app.py
@@ -1,9 +1,7 @@
 from flask import Flask, render_template, send_file, request, session, redirect, url_for, make_response
 from flask_cors import CORS
 
-import numpy as np
 import matplotlib
-matplotlib.use('Agg')
 import matplotlib.pyplot as plt
 from matplotlib.ticker import MaxNLocator
 from io import BytesIO
@@ -17,6 +15,8 @@ from json import loads
 from requests import post
 import jinja2
 
+matplotlib.use('Agg')
+
 db.init_db()
 app = Flask(__name__)
 CORS(app, supports_credentials=True)
@@ -158,13 +158,13 @@ def user_disable_identifier():
         json = request.json
         if "uid" in session and "id" in json:
             db.disable_user_identifier(session["uid"], json["id"])
-    return logout() # force logout
+    return logout()  # force logout
 
 
 @app.route("/coffee/graph_flavors")
 def coffee_graph_flavors():
-    days = request.args.get('days', default = 0, type = int)
-    start = request.args.get('start', default = 0, type = int)
+    days = request.args.get('days', default=0, type=int)
+    start = request.args.get('start', default=0, type=int)
 
     b = BytesIO()
     if "uid" in session:
@@ -299,6 +299,7 @@ def log():
         return data
     return "nope"
 
+
 @app.route("/tellCoffeebot", methods=["POST"])
 def tell_coffeebot():
     err = "Don't worry now! There is a NEW HOPE Tonda is buying NEW PACK!"
index bc53024f4bc90a8b0377923b5720b9b93b910b6d..7fddd8e00336c664bda76f761660ee0d4b342bc1 100644 (file)
@@ -5,26 +5,31 @@ dbdir = os.path.dirname(__file__)
 dbdef = os.path.join(dbdir, "coffee_db.sql")
 dbfile = os.path.join(dbdir, "coffee.db")
 
+
 def open_db():
     conn = sqlite3.connect(dbfile)
     c = conn.cursor()
     return conn, c
 
+
 def close_db(conn):
     conn.commit()
     conn.close()
 
+
 def init_db():
     conn, c = open_db()
     with open(dbdef, "r") as f:
         c.executescript(f.read())
     close_db(conn)
 
+
 def add_user(uid):
     conn, c = open_db()
     c.execute("insert or ignore into users (id) values (?)", (uid,))
     close_db(conn)
 
+
 def add_user_identifier(uid, iid, name):
     # Check if this identifier is not currently associated with different account
     if not get_uid(iid):
@@ -44,19 +49,22 @@ def add_user_identifier(uid, iid, name):
 
         close_db(conn)
 
+
 def disable_user_identifier(uid, iid):
     conn, c = open_db()
     c.execute("update identifiers set active = 0 where userid = ? and id = ?", (uid, iid, ))
     close_db(conn)
 
+
 def get_name(uid):
     conn, c = open_db()
-    for name, in c.execute("select name from users where id = ?",(uid,)):
+    for name, in c.execute("select name from users where id = ?", (uid,)):
         close_db(conn)
         return name
     close_db(conn)
     return None
 
+
 def get_uid(iid):
     conn, c = open_db()
     res = list(c.execute("""
@@ -66,22 +74,26 @@ def get_uid(iid):
 
     return res[0][0] if len(res) > 0 else None
 
+
 def name_user(uid, name):
     conn, c = open_db()
     c.execute("update users set name = ? where id = ?", (name, uid))
     close_db(conn)
 
+
 def rename_user_identifier(uid, iid, name):
     conn, c = open_db()
     c.execute("update identifiers set name = ? where userid = ? and id = ?", (name, uid, iid, ))
     close_db(conn)
 
+
 def list_users():
     conn, c = open_db()
     for row in c.execute("select * from users"):
         print(row)
     close_db(conn)
 
+
 def list_user_identifiers(uid):
     conn, c = open_db()
     res = list(c.execute("""
@@ -94,7 +106,7 @@ def list_user_identifiers(uid):
 def add_coffee(uid, flavor, time=None):
     conn, c = open_db()
     if time is None:
-        c.execute("insert into coffees (id, flavor) values (?,?)", (uid,flavor))
+        c.execute("insert into coffees (id, flavor) values (?,?)", (uid, flavor))
     else:
         c.execute("insert or ignore into coffees (id, flavor, time) values (?,?,?)", (uid, flavor, time))
     close_db(conn)
@@ -114,8 +126,10 @@ def flavors():
     close_db(conn)
     return res
 
+
 def coffee_flavors(uid=None, days=0, start=0):
-    """Returns flavor statistics for team/user during selected period/since beginning.
+    """Returns flavor statistics for team/user during selected
+    period/since beginning.
 
     days -- number of days for computation
     start -- shift size from the current time
@@ -131,7 +145,7 @@ def coffee_flavors(uid=None, days=0, start=0):
     variables = list()
 
     if days is not None and days != 0:
-        query += " where date(time) between date('now', 'localtime', '-"+ str(days+start-1) +" days') and date('now', 'localtime', '-"+ str(start) +" days')"
+        query += " where date(time) between date('now', 'localtime', '-" + str(days+start-1) + " days') and date('now', 'localtime', '-" + str(start) + " days')"
 
         if uid is not None:
             query += " and ids.userid = ? and ids.active"
@@ -151,6 +165,7 @@ def coffee_flavors(uid=None, days=0, start=0):
     close_db(conn)
     return res
 
+
 def coffee_history(uid=None):
     conn, c = open_db()
 
@@ -170,12 +185,13 @@ def coffee_history(uid=None):
             left join
             (select date(time, 'localtime') as time,flavor from coffees co left join identifiers ids on co.id = ids.id where ids.userid = ? and ids.active) c
             on d = date(c.time) group by d, c.flavor
-            """
-            (uid,)))
+            """,
+            (uid,)))
 
     close_db(conn)
     return res
 
+
 def drink_count(uid=None, start=None, stop=None):
     """Return a list of tuples ('<drink type>', <count>).