From 11a23f817f10b8b4eea8ec542cbf673f83306351 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Sun, 14 Jun 2020 14:13:47 -0500 Subject: [PATCH] Make the commands to be ran a list. --- metrics | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/metrics b/metrics index 4f60612..4cdde40 100755 --- a/metrics +++ b/metrics @@ -29,22 +29,29 @@ def sqlite_run(command, db=":memory:", return_output=False): """ conn = sqlite3.connect(db) c = conn.cursor() - c.execute(command) + for cmd in command: + c.execute(cmd) conn.commit() # Make sure we return an output if requested - if return_output: - rows = c.fetchall() - return rows - - conn.close() + try: + if return_output: + rows = c.fetchall() + return rows + except Exception as e: + print(e) + finally: + conn.close() def main(module): """Given a specific module, set it up and insert recent values""" module = module() - sqlite_run(module.sqlite_setup()) - sqlite_run(module.sqlite_add()) + run = [] + run.append(module.sqlite_setup()) + run.append(module.sqlite_add()) + run.append(module.sqlite_time_range(days=10)) + print(sqlite_run(run, return_output=True)) if __name__ == "__main__":