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

updated to newest version.

parent 9ba4c4ee
Branches
Tags
No related merge requests found
Pipeline #48 passed
......@@ -6,8 +6,9 @@ import sqlite3
create_table = """
CREATE TABLE WEB_URL(
LONG_URL TEXT NOT NULL
SHORT_URL TEXT NOT NULL
LONG_URL TEXT NOT NULL,
SHORT_URL TEXT NOT NULL,
USERNAME TEXT
);
"""
with sqlite3.connect('db/urls.db') as conn:
......@@ -20,6 +21,6 @@ with sqlite3.connect('db/urls.db') as conn:
conn = sqlite3.connect('db/urls.db')
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, USERNAME FROM WEB_URL WHERE 1') #read all data from database
for entries in res.fetchall():
print(str(entries[1]).replace('"', "") + ";" + str(entries[0]).replace('"', "")) #format the data and print it to console. with a pipe you can redirect the output to a file e.g. python export.py > urls.csv
\ No newline at end of file
print(str(entries[1]).replace('"', "") + ";" + str(entries[0]).replace('"', "") + ";" + entries[2]) #format the data and print it to console. with a pipe you can redirect the output to a file e.g. python export.py > urls.csv
\ No newline at end of file
......@@ -9,7 +9,8 @@ def table_check(): #Check if database exists
create_table = """
CREATE TABLE WEB_URL(
LONG_URL TEXT NOT NULL,
SHORT_URL TEXT NOT NULL
SHORT_URL TEXT NOT NULL,
USERNAME TEXT
);
"""
with sqlite3.connect('db/urls.db') as conn:
......@@ -35,7 +36,8 @@ with sqlite3.connect('db/urls.db') as conn:
for lines in tqdm(text):
SHORT_URL = lines.split(";")[0].replace("\n", "").replace("\r","") #Split the CSV at the ";" then use the first 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
USERNAME = lines.split(";")[2].replace("\n", "").replace("\r","") #Split the CSV at the ";" then use the thirs one and replace all linebreaks
res = cursor.execute( #Insert the data in the SQL table
'INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)',
[LONG_URL, SHORT_URL.lower()] #replace big letters in short url with small letters.
'INSERT INTO WEB_URL (LONG_URL, SHORT_URL, USERNAME) VALUES (?, ?, ?)',
[LONG_URL, SHORT_URL.lower(), USERNAME] #replace big letters in short url with small letters.
)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment