diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml deleted file mode 100644 index 383e65c..0000000 --- a/.github/workflows/pylint.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Pylint - -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.8", "3.9", "3.10"] - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pylint - - name: Analysing the code with pylint - run: | - pylint $(git ls-files '*.py') diff --git a/merge_sample.py b/merge_sample.py index 8effee7..f473ed1 100644 --- a/merge_sample.py +++ b/merge_sample.py @@ -7,26 +7,29 @@ # oder unter z. B. Ubuntu: apt install python3-xlrd python3-sqlite3 # -import xlrd import sqlite3 +import xlrd SQLITE_FILE = "database.db" -con = sqlite3.connect(SQLITE_FILE) -#con.execute("create table pruefungsergebnis (pruefung_id int not null, mtknr int not null, note decimal(3,1), primary key(pruefung_id, mtknr))") +connection = sqlite3.connect(SQLITE_FILE) + +#con.execute("create table pruefungsergebnis (pruefung_id int not null, "\ +# + "mtknr int not null, note decimal(3,1), primary key(pruefung_id, mtknr))") #con.commit() -# Hier als Konstante, da in der Praxis wahrscheinlich aus Kontext in Webanwendung abgeleitet +# Hier als Konstante, da in der Praxis wahrscheinlich aus Kontext +# in Webanwendung abgeleitet PRUEFUNG_ID = 3 def read_file(filename): # alle Validierungsschritte zugunsten eines übersichtlichen Beispiels eingespart - xlfile = xlrd.open_workbook(filename) - xlsheet = xlfile.sheet_by_index(0) + xlfile = xlrd.open_workbook(filename) + xlsheet = xlfile.sheet_by_index(0) print(f"Importiere aus {filename} - {xlsheet.name}") data = { int(xlsheet.cell(rx, 0).value): xlsheet.cell(rx, 1).value - for rx in range(1, xlsheet.nrows) + for rx in range(1, xlsheet.nrows) } return data @@ -42,11 +45,14 @@ def is_already_set(con, pruefung_id, mtknr): def is_valid_value(pruefung_id, note): # Im realen System z. B. auf der Basis der Notengebungsart etc. prüfen - return note is not None and note in [1, 1.3, 1.7, 2, 2.3, 2.7, 3, 3.3, 3.7, 4, 5] + return note is not None and note in [ + 1, 1.3, 1.7, 2, 2.3, 2.7, 3, 3.3, 3.7, 4, 5 + ] def is_modified(con, pruefung_id, mtknr, note): - sql = "select count(*) as anzahl from pruefungsergebnis where pruefung_id = ? and mtknr = ? and note = ?" + sql = "select count(*) as anzahl from pruefungsergebnis" \ + + " where pruefung_id = ? and mtknr = ? and note = ?" cur = con.cursor() cur.execute(sql, (pruefung_id, mtknr, note)) result = cur.fetchone()[0] @@ -56,19 +62,21 @@ def is_modified(con, pruefung_id, mtknr, note): def merge_data(pruefung_id, new_data): update_sql = "update pruefungsergebnis set note = ? where pruefung_id = ? and mtknr = ?" insert_sql = "insert into pruefungsergebnis (pruefung_id, mtknr, note) values (?, ?, ?)" - with con: # Transaktionsscope: Fehler führt zuverlässig zum Verwerfen aller Änderungen aus einer Excel-Datei + # Transaktionsscope: Fehler führt zuverlässig zum Verwerfen + # aller Änderungen aus einer Excel-Datei + with connection: for mtknr in new_data.keys(): note = new_data[mtknr] - if is_already_set(con, pruefung_id, mtknr): + if is_already_set(connection, pruefung_id, mtknr): if is_valid_value(pruefung_id, note): - if is_modified(con, pruefung_id, mtknr, note): + if is_modified(connection, pruefung_id, mtknr, note): print(f"Wollen Sie die Note zu {mtknr} auf {note} aktualisieren? (j/n)") answer = input() if answer == 'j': - con.execute(update_sql, (note, pruefung_id, mtknr)) - print(f"angepasst") + connection.execute(update_sql, (note, pruefung_id, mtknr)) + print("angepasst") else: - print(f"unverändert") + print("unverändert") else: print(f"Note zu {mtknr} wird nicht geändert, Notenwert unverändert") else: @@ -77,7 +85,7 @@ def merge_data(pruefung_id, new_data): print(f"Mtknr: {mtknr} Note: {note} hinzufügen") # im Falle von HISinOne wegen bereits bestehendem Anmeldesatz auch Update, so aber # einfacher im Beispiel darzustellen... - con.execute(insert_sql, (pruefung_id, mtknr, note)) + connection.execute(insert_sql, (pruefung_id, mtknr, note))