From 7bf176d36b160484f284ab3741f0504706feb564 Mon Sep 17 00:00:00 2001 From: ali jafari Date: Wed, 8 Apr 2020 07:16:14 +0430 Subject: [PATCH 1/2] msspl correction --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e1d9d30..2503624 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This project is done for Altech (Schneider Electric Iran) as an educational seri کل ویدئوها رو می تونین از لینک های زیر ببینین. -Every single step of this project is screen captures and you can follow them [On youtube](https://www.youtube.com/playlist?list=PL-tKrPVkKKE1vAT_rgjnvL_RgFUI9oJ9a) or [On Aparat](https://www.aparat.com/v/fAZSV?playlist=288572). +Every single step of this project is screen captured and you can follow them [On youtube](https://www.youtube.com/playlist?list=PL-tKrPVkKKE1vAT_rgjnvL_RgFUI9oJ9a) or [On Aparat](https://www.aparat.com/v/fAZSV?playlist=288572). ## How to run 1. Install python3, pip3, virtualenv, MySQL in your system. From 147ca047ad07fc06a70730befa9ae96f9aeb5c41 Mon Sep 17 00:00:00 2001 From: ali jafari Date: Wed, 8 Apr 2020 07:18:23 +0430 Subject: [PATCH 2/2] try to use one query instead of four, for fetch all stats --- app/main.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/app/main.py b/app/main.py index 84bf48e..6b4b67d 100644 --- a/app/main.py +++ b/app/main.py @@ -155,29 +155,25 @@ def home(): smss.append({'status': status, 'sender': sender, 'message': message, 'answer': answer, 'date': date}) # collect some stats for the GUI + num_ok = 'error' + num_failure = 'error' + num_double = 'error' + num_notfound = 'error' try: - cur.execute("SELECT count(*) FROM PROCESSED_SMS WHERE status = 'OK'") - num_ok = cur.fetchone()[0] - except: - num_ok = 'error' - - try: - cur.execute("SELECT count(*) FROM PROCESSED_SMS WHERE status = 'FAILURE'") - num_failure = cur.fetchone()[0] - except: - num_failure = 'error' + cur.execute("SELECT status, COUNT(*) FROM PROCESSED_SMS GROUP BY status") + all_stats = cur.fetchall() + for stat in all_stats: + if stat[0] == 'OK': + num_ok = stat[1] + elif stat[0] == 'FAILURE': + num_failure = stat[1] + elif stat[0] == 'DOUBLE': + num_double = stat[1] + elif stat[0] == 'NOT-FOUND': + num_notfound = stat[1] - try: - cur.execute("SELECT count(*) FROM PROCESSED_SMS WHERE status = 'DOUBLE'") - num_double = cur.fetchone()[0] - except: - num_double = 'error' - - try: - cur.execute("SELECT count(*) FROM PROCESSED_SMS WHERE status = 'NOT-FOUND'") - num_notfound = cur.fetchone()[0] except: - num_notfound = 'error' + pass return render_template('index.html', data={'smss': smss, 'ok': num_ok, 'failure': num_failure, 'double': num_double, 'notfound': num_notfound})