From c152e255cddc0e10a254d40bacdac734c83e33d2 Mon Sep 17 00:00:00 2001 From: jonasled <jonas@jonasled.de> Date: Sun, 6 Oct 2019 21:49:01 +0200 Subject: [PATCH] add coments on export --- export.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/export.py b/export.py index 40cd498..45e7569 100644 --- a/export.py +++ b/export.py @@ -1,3 +1,6 @@ +# to run this script and export the database from an docker container run docker -it <container_name> python3 export.py > database.csv +#The output will be in excel-style CSV (";" instead of "," as column seperator.) + import sqlite3 create_table = """ @@ -8,7 +11,7 @@ create_table = """ """ with sqlite3.connect('db/urls.db') as conn: cursor = conn.cursor() - try: #Try making the database structure, if fails Database was already created. + try: #Try making the database structure, if succeeded, exit, because there can't be any data. cursor.execute(create_table) print("No data Found, exiting") exit() @@ -17,6 +20,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') +res = cursor.execute('SELECT LONG_URL, SHORT_URL FROM WEB_URL WHERE 1') #read all data from database for entries in res.fetchall(): - print(str(entries[1]) + ";" + str(entries[0])) \ No newline at end of file + print(str(entries[1]) + ";" + str(entries[0])) #format the data and print it to console. \ No newline at end of file -- GitLab