Last active
June 30, 2021 16:39
-
-
Save OnSive/b33a36f938319d5d411c31dcb421a1a4 to your computer and use it in GitHub Desktop.
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 10000000001;Daniel Hilbrand;1 | |
| 10000000002;Korbinian Gabler;2 | |
| 10000000003;Felix Schaidnagel;3 | |
| 10000000004;Simon Vogler;4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from urllib.request import pathname2url | |
| import os.path | |
| import sqlite3 | |
| import csv | |
| db = r'karten.db' | |
| con = sqlite3.connect(db) | |
| cur = con.cursor() | |
| def CheckDatabase(): | |
| global cur | |
| cur.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='karten'") | |
| if cur.fetchone()[0] == 0 : | |
| cur.execute("CREATE TABLE karten (id int, name text, azubi_nr int)") | |
| con.commit() | |
| def ImportData(): | |
| with open('data.csv', newline='') as csvfile: | |
| spamreader = csv.reader(csvfile, delimiter=';', quotechar='|') | |
| for row in spamreader: | |
| cur.execute("SELECT count(id) FROM karten WHERE id=" + row[0]) | |
| if cur.fetchone()[0] == 0 : | |
| cur.execute("INSERT INTO karten VALUES (?, ?, ?)", (row[0], row[1], row[2])) | |
| else: | |
| cur.execute("UPDATE karten SET name='" + row[1] + "', azubi_nr=" + row[2] + " WHERE id=" + row[0]) | |
| # Ausgabe für eingelesene Daten | |
| print('--'.join(row)) | |
| con.commit() | |
| CheckDatabase() | |
| ImportData() | |
| while True: | |
| if not os.path.isfile("test.txt"): | |
| continue | |
| file = open('test.txt',mode='r') | |
| karten_nr = file.read() | |
| file.close() | |
| os.remove('test.txt') | |
| cur.execute("SELECT * FROM karten WHERE id=" + str(karten_nr)) | |
| karte = cur.fetchone() | |
| # Text für Bildschirm zusammenbauen | |
| ausgabe = "Hallo " + str(karte[1]) + " (" + str(karte[2]) + ")" | |
| # Text ausgeben | |
| print(ausgabe) | |
| con.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 10000000003 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment