浏览代码

Kommentare importieren und aufbereiten

gc-server3 1 周之前
父节点
当前提交
d977988e1c
共有 1 个文件被更改,包括 39 次插入0 次删除
  1. 39 0
      app/cleanup_comments.py

+ 39 - 0
app/cleanup_comments.py

@@ -0,0 +1,39 @@
+from datetime import timedelta
+
+from db import get_session
+import re
+from sqlalchemy import text
+
+
+def main():
+    db = next(get_session())
+    q = db.execute(text("SELECT * FROM dbo.Forderungen_Kommentar_Rohdaten"))
+
+    for row in q.fetchall():
+        for i, r in enumerate(row.Kommentar.split("\n"), 1):
+            comment_date = row.Timestamp + timedelta(minutes=i)
+            comment_user = row.Benutzer_ID
+            r = r.replace("'", "")
+            db.execute(
+                text(
+                    "INSERT INTO dbo.Forderungen_Kommentar "
+                    f"VALUES ('{row.Client_DB}', '{row.Beleg_Nr}', '{comment_date}', '{comment_user}', '{r}')"
+                )
+            )
+            # m = re.search(r"(\d\d\.\d\d?)\.?[\/\s](\w+)", r)
+            # if m:
+            #     comment_date = m[1]
+            #     comment_user = m[2]
+            # else:
+            #     if r.startswith("EWB"):
+            #         continue
+            #     az = re.search(r"^AZ\:?\s(\d+\/\d+)", r)
+            #     if az:
+            #         continue
+            #     print(r)
+
+    db.commit()
+
+
+if __name__ == "__main__":
+    main()