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. 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})