From 6365fb276e08d75d76b5ecdcb20c43cde0c09761 Mon Sep 17 00:00:00 2001
From: jonasled <jonas@jonasled.de>
Date: Fri, 17 Jan 2020 16:10:31 +0100
Subject: [PATCH] added counter to dashboard

---
 main.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/main.py b/main.py
index 4baa1ee..c6e760c 100644
--- a/main.py
+++ b/main.py
@@ -321,11 +321,16 @@ def ownLinks():
     with sqlite3.connect('db/urls.db') as conn:
         cursor = conn.cursor()
         res = cursor.execute('SELECT LONG_URL, SHORT_URL FROM WEB_URL WHERE USERNAME=?', [userID]) #Get all entries from the database, that are created by this user
-        response = '<table id="t01">\n<tr>\n<th>Long URL</th>\n<th>Short URL</th>\n<th>Action</th>\n</tr>\n' #This is the layout of the table
+        response = '<table id="t01">\n<tr>\n<th>Long URL</th>\n<th>Short URL</th>\n<th>Views</th>\n<th>Action</th>\n</tr>\n' #This is the layout of the table
         try:
             entriesList = res.fetchall()
             for entries in entriesList: #for every entrie in the database add a line to the table
-                response = response + "<tr>\n<td>" + entries[0] + "</td>\n<td>" + entries[1] + '</td>\n<td><a id="red" href="/user/delete?link=' + escape(entries[1]) + '">delete</a> <a href="#" id="dialog-link" onclick="buttonListener(\'' + entries[1] + '\', this)">QR</a></tr>\n'
+                cursor2 = conn.cursor()
+                try:
+                    calls = str(cursor2.execute('SELECT CALLS FROM ANALYTICS WHERE SHORT_URL=?', [entries[1]]).fetchone()[0])
+                except:
+                    calls = "0"
+                response = response + "<tr>\n<td>" + entries[0] + "</td>\n<td>" + entries[1] + '</td>\n<td>' + calls + '</td>\n<td><a id="red" href="/user/delete?link=' + escape(entries[1]) + '">delete</a> <a href="#" id="dialog-link" onclick="buttonListener(\'' + entries[1] + '\', this)">QR</a></tr>\n'
             response = response + "</table>" #Close the table
             if(len(entriesList) == 0): response = 'you have no shorten links.' #If user has no shorten links make this message
         except:
-- 
GitLab