Seite 2 von 2

Re: 2 programme verbinden

Verfasst: Montag 31. Januar 2022, 18:07
von Sirius3
`now` heißt in `update_database` `timestamp`:

Code: Alles auswählen

def update_database(mydb, timestamp, card_id):
    with closing(mydb.cursor()) as cursor:
        cursor.execute("SELECT * FROM db where db04 = %s", [card_id])
        # TODO: explicitly name the fields to query
        result = cursor.fetchone()
        if result is not None:
            # TODO: find readable names for the fields and table.
            # TODO: Remove result, due to normalization
            cursor.execute("INSERT INTO iss (vsb01, vsb02, vsb03, vsb04, vsb05, vsb06, vsb07, vsb08, vsb09, vsb10, vsb11, vsb12) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",[
                result[1], result[2], result[3], result[4],
                timestamp.strftime('%Y-%m-%d'), # TODO: use timestamp only
                "Training",
                card_id,
                "Weisweil",
                timestamp.strftime('%Y'), # TODO: remove extra year field
                timestamp.strftime('%H:%M:%S'), # TODO: remove extra time field"
                "",
                "",
            ])
            mydb.commit()
            print(card_id)
            return "iss-Eintrag"
        else:
            cursor.execute("SELECT cd01 FROM cd where cd01 = %s", [card_id])
            result = cursor.fetchone()
            if result is not None:
                print("Karte ist schon vorhanden.")
                return "schon da"
            else:
                # TODO: find readable names for the fields and table.
                cursor.execute("INSERT INTO cd (cd01, cd02, cd03) VALUES (%s, %s, %s)", [
                    card_id, "f", "n",
                ])
                mydb.commit()
                print(f"{card_id} wurde eingetragen")
                return "cd-Eintrag"