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

add coments on export

parent 6a1ae5f9
No related branches found
No related tags found
No related merge requests found
# 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 import sqlite3
create_table = """ create_table = """
...@@ -8,7 +11,7 @@ create_table = """ ...@@ -8,7 +11,7 @@ create_table = """
""" """
with sqlite3.connect('db/urls.db') as conn: with sqlite3.connect('db/urls.db') as conn:
cursor = conn.cursor() 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) cursor.execute(create_table)
print("No data Found, exiting") print("No data Found, exiting")
exit() exit()
...@@ -17,6 +20,6 @@ with sqlite3.connect('db/urls.db') as conn: ...@@ -17,6 +20,6 @@ with sqlite3.connect('db/urls.db') as conn:
conn = sqlite3.connect('db/urls.db') 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') 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]) + ";" + str(entries[0])) print(str(entries[1]) + ";" + str(entries[0])) #format the data and print it to console.
\ No newline at end of file \ 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