ifnoterror_404:#If there was no 404 error before, redirect the user. If not throw a 404 error
res=cursor.execute('SELECT CALLS FROM ANALYTICS WHERE SHORT_URL=?',[host+"/"+short_url.lower()])
try:
calls=res.fetchone()[0]+1
row=row=cursor.fetchone()
ifnotrowisNone:
calls=row[0]+1
cursor.execute('UPDATE ANALYTICS SET CALLS = ? WHERE SHORT_URL=?',(str(calls),host+"/"+short_url.lower()))
except:
print(Exception)
else:
cursor.execute('INSERT INTO ANALYTICS (SHORT_URL) VALUES ("'+host+"/"+short_url.lower()+"\")")
returnredirect(url)#I use temp redirect here, because the owner of a link can delete it. If then the link is reused, the user will maybe redirected to the wrong page