3 Commits d37f5bbfc4 ... 23a9cd47d5

Author SHA1 Message Date
  gc-server3 23a9cd47d5 Sandbox 7 months ago
  gc-server3 d20fab087e Tools für S+K 7 months ago
  gc-server3 f342dbe457 Neue Credentials 7 months ago
5 changed files with 95 additions and 7 deletions
  1. 2 1
      contacts/o365_copy.py
  2. 24 0
      sandbox/hash_list.py
  3. 6 6
      sandbox/sudoku_solver.py
  4. 27 0
      tasks_tools/copy_and_import.py
  5. 36 0
      tasks_tools/wait.py

+ 2 - 1
contacts/o365_copy.py

@@ -2,7 +2,7 @@ from O365 import Account
 from O365.address_book import Contact
 
 client_id = "925f74dc-f96a-4718-9ca7-d6cc3fa43e1e"
-client_secret = "SS~8Q~QpBZV9toZuwkzW1XGGen2Hn833spNMtdq5"
+client_secret = "SMn8Q~rVUnbYEAtEZZ6jcQElOIU9tDQUgv1VwcRz"
 
 account = Account(
     (client_id, client_secret), auth_flow_type="credentials", tenant_id="2ad0dff5-07ce-4cc2-a852-99ce8b91c218"
@@ -17,6 +17,7 @@ mailboxes = [
     "m.geiss@global-cube.net",
     "matarrelli@global-cube.net",
     "winkler@global-cube.net",
+    "karaca@global-cube.net",
 ]
 
 

+ 24 - 0
sandbox/hash_list.py

@@ -0,0 +1,24 @@
+import hashlib
+import io
+from pathlib import Path
+
+
+def get_hash(filename):
+    with open(filename, "r", encoding="latin-1", buffering=0) as frh:
+        with open(filename + ".sha", "w", encoding="latin-1") as fwh:
+            chunk = io.StringIO()
+            for i, line in enumerate(frh.readlines()):
+                chunk.write(line)
+                if i % 1000 == 0:
+                    m = hashlib.sha256(chunk.getvalue().encode())
+                    chunk.truncate(0)
+                    fwh.write(m.hexdigest() + "\n")
+
+
+def main():
+    for f in Path("datev/data").glob("*.csv"):
+        get_hash(str(f))
+
+
+if __name__ == "__main__":
+    main()

+ 6 - 6
sandbox/sudoku_solver.py

@@ -2,7 +2,7 @@ class Board:
     symbols = "123456789"
     blank = "."
 
-    _board = ['.' * 10 for i in range(9)]
+    _board = ["." * 10 for i in range(9)]
 
     def set_initial(self, board: list):
         self._board = board.copy()
@@ -16,16 +16,16 @@ class Board:
     def get_block(self, x, y):
         row = x // 3
         col = y // 3
-        return [r[col * 3:(col + 1) * 3] for r in self._board[row * 3:(row + 1) * 3]]
+        return [r[col * 3 : (col + 1) * 3] for r in self._board[row * 3 : (row + 1) * 3]]
 
     def is_blank(self, x, y):
         return self._board[x][y] == self.blank
-    
+
     def is_solved(self):
         return self.blank not in "".join(self._board)
 
     def set_cell(self, x, y, value):
-        self._board[x] = self._board[x][:y] + value + self._board[x][y + 1:]
+        self._board[x] = self._board[x][:y] + value + self._board[x][y + 1 :]
 
     def get_possibilities(self, x, y):
         all_symbols = list(self.get_row(x) + self.get_col(y) + "".join(self.get_block(x, y)))
@@ -40,12 +40,12 @@ class Board:
                 if self.is_blank(i, j) and len(self.get_possibilities(i, j)) == 1:
                     return (i, j)
         return None
-    
+
     def get_next_blank(self):
         for i in range(9):
             for j in range(9):
                 if self.is_blank(i, j):
-                    return (i, j)        
+                    return (i, j)
 
     def solve(self):
         while cell := self.get_unique_cell():

+ 27 - 0
tasks_tools/copy_and_import.py

@@ -0,0 +1,27 @@
+import calendar
+import datetime
+
+import typer
+
+filename = "test.csv"
+archive_folder = "Archiv"
+
+
+def main():
+    today = datetime.datetime.now().date()
+    end_of_month = last_day_of_month(today)
+
+    last_month = today - datetime.timedelta(days=30)
+    end_of_last_month = last_day_of_month(last_month)
+
+    if today == end_of_month:
+        archive_filename = archive_folder + "\\" + filename[:-4] + "_" + today.isoformat() + filename[-4:]
+
+
+def last_day_of_month(any_date: datetime.date) -> datetime.date:
+    end_of_month = calendar.monthrange(any_date.year, any_date.month)[2]
+    return datetime.date(any_date.year, any_date.month, end_of_month)
+
+
+if __name__ == "__main__":
+    typer.run(main)

+ 36 - 0
tasks_tools/wait.py

@@ -0,0 +1,36 @@
+import time
+from datetime import datetime, timedelta
+from pathlib import Path
+
+import typer
+
+
+def main(filename: str, tolerance: int = 12, duration: int = 6):
+    now_ts = datetime.now()
+    max_ts = now_ts + timedelta(hours=duration)
+    file_mtime_ts = datetime.fromtimestamp(Path(filename).stat().st_mtime)
+
+    print(f"Warte auf Datei {filename}")
+    print("Aktuelle Uhrzeit:   " + now_ts.strftime("%d.%m.%Y %H:%M:%S"))
+    print("Aenderungsdatum:    " + file_mtime_ts.strftime("%d.%m.%Y %H:%M:%S"))
+    print("Maximale Wartezeit: " + max_ts.strftime("%d.%m.%Y %H:%M:%S"))
+    print("")
+
+    while now_ts < max_ts:
+        now_ts = datetime.now()
+        file_mtime_ts = datetime.fromtimestamp(Path(filename).stat().st_mtime)
+
+        oldest_ts = now_ts - timedelta(hours=tolerance)
+        newest_ts = now_ts - timedelta(minutes=10)
+
+        if file_mtime_ts >= oldest_ts and file_mtime_ts <= newest_ts:
+            print(f"\nDatei {filename} ist bereit")
+            return
+        print(".", end="")
+        time.sleep(60)
+    print(f"\n!! Datei {filename} ist nicht aktuell. Warten beendet !!")
+    exit(1)
+
+
+if __name__ == "__main__":
+    typer.run(main)