diff --git a/export.py b/export.py index 06bd49e1be04cf07a36de600c8a3e8b155ab8a8c..70ad0f62a5aba64c424099587025e41d8973e3a1 100644 --- a/export.py +++ b/export.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # 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.) diff --git a/import.py b/import.py index 5f937af46dede37af2f5f9f6900f8e3f12cd1a82..976ce4b57866686b4ea082dc09e25d90e1c7849d 100644 --- a/import.py +++ b/import.py @@ -1,7 +1,9 @@ +#!/usr/bin/env python3 #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 import sqlite3 import os +from tqdm import tqdm def table_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 - for lines in text: - print("Importing " + str(counter) + " from " + str(entries)) #Make a progress message (mormaly unnecessary, because import is to quick (<1s)) + 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 res = cursor.execute( #Insert the data in the SQL table 'INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)', [LONG_URL, SHORT_URL.lower()] - ) - counter = counter + 1 #Add 1 to counter, for progress \ No newline at end of file + ) \ No newline at end of file diff --git a/main.py b/main.py index 8ee5f82f223018149623a092b116283cf6bbb65c..be287dcc2e92fa1c89fd98aa815317c46937821c 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from waitress import serve from flask import Flask, request, render_template, redirect, abort, Markup import sqlite3