#To import data you need a excel style CSV (";" as seperator) with the first as short url (e.g. kurz.ml/example) and in the seccond row the long url (e.g http://example.com).
#Then run docker -it <container_name> python3 import.py Now you can paste the CSV as text and press enter again at the end
importsqlite3
importos
fromtqdmimporttqdm
deftable_check():#Check if database exists
create_table="""
CREATE TABLE WEB_URL(
...
...
@@ -30,13 +32,10 @@ with sqlite3.connect('db/urls.db') as conn:
break
text=lines
entries=len(text)#Count the entries (for the output in the for loop)
counter=1
forlinesintext:
print("Importing "+str(counter)+" from "+str(entries))#Make a progress message (mormaly unnecessary, because import is to quick (<1s))
forlinesintqdm(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
res=cursor.execute(#Insert the data in the SQL table
'INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)',