diff --git a/export.py b/export.py index 40cd498ecd822a2052fc6a2141e34d70a4406208..45e7569f4ba536928e4fca2b3cae14752ec1967f 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