step1.py udated
This commit is contained in:
16
GUI/import_gui.py
Normal file
16
GUI/import_gui.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from kivy.app import App
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
from kivy.uix.image import Image
|
||||
|
||||
|
||||
class ImportGUI(App):
|
||||
def build(self):
|
||||
self.window = GridLayout()
|
||||
self.window.cols = 3
|
||||
self.window.add_widget(Image(source="add.png"))
|
||||
|
||||
return self.window
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ImportGUI().run()
|
||||
@@ -1 +1,7 @@
|
||||
# UCS Import mit Python Script
|
||||
|
||||
© Patrick vom Hagen - 2024
|
||||
|
||||
## Konzept
|
||||
|
||||
Mit diesem Tool soll ein Listenabgleich zwischen einer neuen Liste einer
|
||||
@@ -8,18 +8,18 @@ def check_file(path):
|
||||
result = chardet.detect(file.read())
|
||||
|
||||
detected_encoding = result['encoding']
|
||||
try:
|
||||
pd.read_csv(path, encoding=detected_encoding)
|
||||
except pd.errors.ParserError as e:
|
||||
# Wenn ein Parserfehler auftritt, gibt eine Fehlermeldung aus
|
||||
print(f"Fehler beim Einlesen der CSV-Datei: {e}")
|
||||
print()
|
||||
data = open(path, "r")
|
||||
data = ''.join([i for i in data]).replace(",", "")
|
||||
x = open(path, "w")
|
||||
x.writelines(data)
|
||||
x.close()
|
||||
print(f"Alle Kommas entfernt")
|
||||
# try:
|
||||
# pd.read_csv(path, encoding=detected_encoding)
|
||||
# except pd.errors.ParserError as e:
|
||||
# # Wenn ein Parserfehler auftritt, gibt eine Fehlermeldung aus
|
||||
# print(f"Fehler beim Einlesen der CSV-Datei: {e}")
|
||||
# print()
|
||||
# data = open(path, "r")
|
||||
# data = ''.join([i for i in data]).replace(",", "")
|
||||
# x = open(path, "w")
|
||||
# x.writelines(data)
|
||||
# x.close()
|
||||
# print(f"Alle Kommas entfernt")
|
||||
|
||||
|
||||
# Prüft Formatierung der CSV, formatiert diese zu utf-8 und speichert das Ergebnis als neue Liste
|
||||
@@ -30,6 +30,7 @@ def format_csv(path, type):
|
||||
detected_encoding = result['encoding']
|
||||
|
||||
# CSV-Datei mit Pandas einlesen
|
||||
# in step1 nicht notwendig, da nicht mit csv, sondern mit pandas frame gearbeitet wird
|
||||
try:
|
||||
df = pd.read_csv(path, encoding=detected_encoding)
|
||||
print("Datei erfolgreich eingelesen.")
|
||||
|
||||
3
main.py
3
main.py
@@ -7,6 +7,7 @@
|
||||
###############################################################
|
||||
# IMPORT - standard Python imports für benötigte Bibliotheken #
|
||||
|
||||
from src import step1
|
||||
import pandas as pd # pandas für Datenmanagement
|
||||
import chardet # chardet erkennt Formatierung - Umwandlung des erkannten Formats in UTF-8
|
||||
import csv # zur Verarbeitung von .csv Dateien
|
||||
@@ -50,6 +51,8 @@ if __name__ == "__main__":
|
||||
else:
|
||||
del_zeros = True
|
||||
|
||||
# step1.check_file()
|
||||
|
||||
# ---------------------------------------------------- #
|
||||
# Step 2 - auf name, vorname reduzieren und abgleichen #
|
||||
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
panads
|
||||
chardet
|
||||
chardet~=5.2.0
|
||||
Kivy~=2.3.0
|
||||
pandas~=2.0.3
|
||||
Levenshtein~=0.23.0
|
||||
40
src/step1.py
40
src/step1.py
@@ -0,0 +1,40 @@
|
||||
import pandas as pd
|
||||
import chardet
|
||||
import csv
|
||||
|
||||
|
||||
# prüft aktuelles Format mittels chardet Lib
|
||||
def check_export_file(path):
|
||||
with open(path, 'rb') as file:
|
||||
result = chardet.detect(file.read())
|
||||
|
||||
detected_encoding = result['encoding']
|
||||
|
||||
# Try: Datei in pandas einlesen
|
||||
try:
|
||||
return pd.read_csv(path, encoding=detected_encoding)
|
||||
# Catch: zusätzliche Kommas entfernen
|
||||
except pd.errors.ParserError as e:
|
||||
# Wenn ein Parserfehler auftritt, gibt eine Fehlermeldung aus
|
||||
print(f"Fehler beim Einlesen der CSV-Datei: {e}")
|
||||
print()
|
||||
data = open(path, "r")
|
||||
data = ''.join([i for i in data]).replace(",", "")
|
||||
x = open(path, "w")
|
||||
x.writelines(data)
|
||||
x.close()
|
||||
print(f"Alle Kommas entfernt, einlesen wir erneut versucht ...")
|
||||
# Nach Komma Ersetzung erneut versuchen
|
||||
try:
|
||||
return pd.read_csv(path, encoding=detected_encoding)
|
||||
except pd.errors.ParserError as e:
|
||||
print(f"Erneut Fehler in CSV-Datei: {e}")
|
||||
print(f"Datei muss manuell geändert werden.")
|
||||
|
||||
|
||||
# zum Einlesen der bisherigen Systemdaten
|
||||
def create_dataframe_system(path):
|
||||
try:
|
||||
return pd.read_csv(path, encoding='utf')
|
||||
except pd.errors.ParserError as e:
|
||||
print(f"Fehler beim Einlesen der CSV")
|
||||
|
||||
Reference in New Issue
Block a user