Skip to content
Snippets Groups Projects
Commit a52a2b44 authored by Jonas Leder's avatar Jonas Leder
Browse files

removed problems with encoded strings

parent eaa23ebe
No related branches found
No related tags found
No related merge requests found
...@@ -21,4 +21,4 @@ conn = sqlite3.connect('db/urls.db') ...@@ -21,4 +21,4 @@ conn = sqlite3.connect('db/urls.db')
cursor = conn.cursor() cursor = conn.cursor()
res = cursor.execute('SELECT LONG_URL, SHORT_URL FROM WEB_URL WHERE 1') #read all data from database res = cursor.execute('SELECT LONG_URL, SHORT_URL FROM WEB_URL WHERE 1') #read all data from database
for entries in res.fetchall(): for entries in res.fetchall():
print(str(entries[1]).replace('"', "") + ";" + str(entries[0]).replace('"', "")) #format the data and print it to console. print(str(entries[1]).replace('"', "") + ";" + str(entries[0]).replace('"', "")) #format the data and print it to console.
\ No newline at end of file \ No newline at end of file
...@@ -37,6 +37,6 @@ with sqlite3.connect('db/urls.db') as conn: ...@@ -37,6 +37,6 @@ with sqlite3.connect('db/urls.db') as conn:
LONG_URL = lines.split(";")[1].replace("\n", "").replace("\r","") #Split the CSV at the ";" then use the seccond one and replace all linebreaks LONG_URL = lines.split(";")[1].replace("\n", "").replace("\r","") #Split the CSV at the ";" then use the seccond one and replace all linebreaks
res = cursor.execute( #Insert the data in the SQL table res = cursor.execute( #Insert the data in the SQL table
'INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)', 'INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)',
[LONG_URL, SHORT_URL] [LONG_URL, SHORT_URL.lower()]
) )
counter = counter + 1 #Add 1 to counter, for progress counter = counter + 1 #Add 1 to counter, for progress
\ No newline at end of file
...@@ -79,7 +79,7 @@ def home(): ...@@ -79,7 +79,7 @@ def home():
return render_template('home.html', builddate=builddate, domain=domain_prepared, snackbar="Please enter a short name, before submitting this form", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')]) #return the user the prefilled form with an error message, because no short link was provided return render_template('home.html', builddate=builddate, domain=domain_prepared, snackbar="Please enter a short name, before submitting this form", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')]) #return the user the prefilled form with an error message, because no short link was provided
shorturl = (request.form.get('domain') + "/" + request.form.get('short')).lower() shorturl = (request.form.get('domain') + "/" + request.form.get('short')).lower()
url = str.encode(request.form.get('url')) url = request.form.get('url')
with sqlite3.connect('db/urls.db') as conn: #Check if another user already used the short link with sqlite3.connect('db/urls.db') as conn: #Check if another user already used the short link
cursor = conn.cursor() cursor = conn.cursor()
res = cursor.execute('SELECT LONG_URL FROM WEB_URL WHERE SHORT_URL=?', [shorturl]) res = cursor.execute('SELECT LONG_URL FROM WEB_URL WHERE SHORT_URL=?', [shorturl])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment