cleanup_comments.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from datetime import timedelta
  2. from db import get_session
  3. import re
  4. from sqlalchemy import text
  5. def main():
  6. db = next(get_session())
  7. q = db.execute(text("SELECT * FROM dbo.Forderungen_Kommentar_Rohdaten"))
  8. for row in q.fetchall():
  9. for i, r in enumerate(row.Kommentar.split("\n"), 1):
  10. comment_date = row.Timestamp + timedelta(minutes=i)
  11. comment_user = row.Benutzer_ID
  12. r = r.replace("'", "")
  13. db.execute(
  14. text(
  15. "INSERT INTO dbo.Forderungen_Kommentar "
  16. f"VALUES ('{row.Client_DB}', '{row.Beleg_Nr}', '{comment_date}', '{comment_user}', '{r}')"
  17. )
  18. )
  19. # m = re.search(r"(\d\d\.\d\d?)\.?[\/\s](\w+)", r)
  20. # if m:
  21. # comment_date = m[1]
  22. # comment_user = m[2]
  23. # else:
  24. # if r.startswith("EWB"):
  25. # continue
  26. # az = re.search(r"^AZ\:?\s(\d+\/\d+)", r)
  27. # if az:
  28. # continue
  29. # print(r)
  30. db.commit()
  31. if __name__ == "__main__":
  32. main()