forked from beeware/briefcase-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split services and utils, removed orm
- Loading branch information
1 parent
bacb2b4
commit ce4fea4
Showing
90 changed files
with
2,075 additions
and
692 deletions.
There are no files selected for viewing
Empty file.
55 changes: 55 additions & 0 deletions
55
{{ cookiecutter.app_name }}/src/{{ cookiecutter.module_name }}/services/standard/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from .setup_folders import setup_folders | ||
from .ensure_folder_exists import ensure_folder_exists | ||
from .ensure_base_folder_exits import ensure_base_folder_exits | ||
from .open_file import open_file | ||
from .get_updates_datei_user import get_updates_datei_user | ||
from .get_updates_pdf_path import get_updates_pdf_path | ||
from .update_daten_laden_user import update_daten_laden_user | ||
from .update_daten_laden_app import update_daten_laden_app | ||
from .get_updates_datei_app import get_updates_datei_app | ||
from .update_in_updates_ordner_uebertragen import update_in_updates_ordner_uebertragen | ||
from .get_help_file_path import get_help_file_path | ||
from .get_base_dir import get_base_dir | ||
from .get_settings import get_settings | ||
from .set_settings import set_settings | ||
from .get_settings_file_path import get_settings_file_path | ||
from .set_user_code import set_user_code | ||
from .set_api_key import set_api_key | ||
from .audio_zu_text_konvertieren import audio_zu_text_konvertieren | ||
from .load_settings import load_settings | ||
from .measure_execution_time import measure_execution_time | ||
from .ermittel_den_aktuellen_monat_als_deutsches_wort import ermittel_den_aktuellen_monat_als_deutsches_wort | ||
from .ermittel_den_aktuellen_monat_als_deutsches_wort import ermittel_den_aktuellen_monat_als_deutsches_wort | ||
from .set_beweismittel_data_Scheidung import set_beweismittel_data_Scheidung | ||
from .get_beweismittel_data_scheidung import get_beweismittel_data_scheidung | ||
from .set_beweismittel_data_OWi import set_beweismittel_data_OWi | ||
from .get_beweismittel_data_OWi import get_beweismittel_data_OWi | ||
from .set_lawyer_data import set_lawyer_data | ||
from .get_lawyer_data import get_lawyer_data | ||
from .setup_folders import setup_folders | ||
from .vorlagen_in_vorlagen_ordner_uebertragen import vorlagen_in_vorlagen_ordner_uebertragen | ||
from .anwalt_liste_in_basis_ordner_uebertragen import anwalt_liste_in_basis_ordner_uebertragen | ||
from .get_temp_folder import get_temp_folder | ||
from .get_base_dir import get_base_dir | ||
from .get_template_folder import get_template_folder | ||
from .get_update_folder import get_update_folder | ||
from .get_mandanten_folder import get_mandanten_folder | ||
from .get_temp_file_for_template_file import get_temp_file_for_template_file | ||
from .print_paragraph_details import print_paragraph_details | ||
from .datenabfrage_datev_for_aktenzeichen import datenabfrage_datev_for_aktenzeichen | ||
from .get_nutzername import get_nutzername | ||
from .set_nutzername import set_nutzername | ||
from .get_datev_example_data import get_datev_example_data | ||
from .hinzufuegen_anwaltsdaten_zum_kontext import hinzufuegen_anwaltsdaten_zum_kontext | ||
from .add_ausfuehrung import add_ausfuehrung | ||
from .mark_ausfuehrung_as_fehlerhaft import mark_ausfuehrung_as_fehlerhaft | ||
from .open_file import open_file | ||
from .get_help_file_path import get_help_file_path | ||
from .get_updates_datei_user import get_updates_datei_user | ||
from .get_updates_pdf_path import get_updates_pdf_path | ||
from .update_daten_laden_user import update_daten_laden_user | ||
from .update_daten_laden_app import update_daten_laden_app | ||
from .get_updates_datei_app import get_updates_datei_app | ||
from .update_in_updates_ordner_uebertragen import update_in_updates_ordner_uebertragen | ||
from .versionsordner_erstellen import versionsordner_erstellen | ||
from .wrapper import wrapper |
19 changes: 19 additions & 0 deletions
19
...utter.app_name }}/src/{{ cookiecutter.module_name }}/services/standard/add_ausfuehrung.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from datetime import datetime | ||
import json | ||
import uuid | ||
|
||
def add_ausfuehrung(reference, kundenprogramm_ID, antrags_name): | ||
ensure_data_file_exists() | ||
new_ausfuehrung = { | ||
"id": str(uuid.uuid4()), | ||
"reference": reference, | ||
"kundenprogramm_ID": kundenprogramm_ID, | ||
"datum": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), | ||
"antrags_name": antrags_name, | ||
"fehlerhaft": False | ||
} | ||
with open(get_ausfuehrungen_file_path(), "r+") as file: | ||
data = json.load(file) | ||
data.append(new_ausfuehrung) | ||
file.seek(0) | ||
json.dump(data, file, indent=4) |
38 changes: 38 additions & 0 deletions
38
...cookiecutter.module_name }}/services/standard/anwalt_liste_in_basis_ordner_uebertragen.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import shutil | ||
from datetime import datetime | ||
import os | ||
|
||
def anwalt_liste_in_basis_ordner_uebertragen(app): | ||
kundendaten_ordner_app = os.path.join(app.paths.app, "resources", KUNDENDATEN_ORDNER_APP) | ||
basis_ordner_user = get_base_dir() # Angenommen, diese Funktion gibt den Basisordner des Benutzers zurück | ||
archiv_ordner = os.path.join(basis_ordner_user,ARCHIV_ORDNER, "archivierte_anwalt_daten") | ||
name_der_anwalt_daten_json_datei = "lawyer_details.json" | ||
update_datei_name = "update_lawyer_details.json" | ||
|
||
ziel_datei_pfad = os.path.join(basis_ordner_user, name_der_anwalt_daten_json_datei) | ||
update_datei_pfad = os.path.join(kundendaten_ordner_app, update_datei_name) | ||
|
||
# Stelle sicher, dass der Archivordner existiert | ||
if not os.path.exists(archiv_ordner): | ||
os.makedirs(archiv_ordner) | ||
|
||
# Überprüfe, ob die Datei lawyer_details.json bereits im Zielordner existiert | ||
if os.path.isfile(ziel_datei_pfad): | ||
# Wenn ja, und update_lawyer_details.json ist vorhanden, archiviere die alte Datei | ||
if os.path.isfile(update_datei_pfad): | ||
# Generiere einen eindeutigen Namen für die archivierte Datei | ||
datumsanhang = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") | ||
archivierte_datei_name = f"lawyer_details_{datumsanhang}.json" | ||
archivierte_datei_pfad = os.path.join(archiv_ordner, archivierte_datei_name) | ||
|
||
# Verschiebe die alte lawyer_details.json in den Archivordner | ||
shutil.move(ziel_datei_pfad, archivierte_datei_pfad) | ||
|
||
# Kopiere die update_lawyer_details.json in den Zielordner und benenne sie um | ||
shutil.copy(update_datei_pfad, ziel_datei_pfad) | ||
|
||
else: | ||
# Wenn keine lawyer_details.json im Zielordner, kopiere diese aus dem Kundendatenordner, falls vorhanden | ||
source_datei_pfad = os.path.join(kundendaten_ordner_app, name_der_anwalt_daten_json_datei) | ||
if os.path.isfile(source_datei_pfad): | ||
shutil.copy(source_datei_pfad, ziel_datei_pfad) |
9 changes: 9 additions & 0 deletions
9
...ame }}/src/{{ cookiecutter.module_name }}/services/standard/audio_zu_text_konvertieren.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import whisper | ||
|
||
def audio_zu_text_konvertieren(audio_dateipfad): | ||
# wenn verwendet wir muss openai-whisper installiert sein | ||
import whisper | ||
|
||
model = whisper.load_model("base") | ||
result = model.transcribe(audio_dateipfad) | ||
return result["text"] |
25 changes: 25 additions & 0 deletions
25
...c/{{ cookiecutter.module_name }}/services/standard/datenabfrage_datev_for_aktenzeichen.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import requests | ||
from requests.auth import HTTPBasicAuth | ||
|
||
def datenabfrage_datev_for_aktenzeichen(aktenzeichen:str, passwort:str): | ||
url = 'https://localhost:58452/datev/api/law/v1/files/' | ||
params = { | ||
'select': 'id, name, number', | ||
'filter': f"file_number eq '{aktenzeichen}'", # Verwendung eines f-Strings zur Einsetzung | ||
'orderby': 'my_property_name desc,other_property_name asc', | ||
'top': '100', | ||
'skip': '10' | ||
} | ||
headers = { | ||
'accept': 'application/json; charset=utf-8' | ||
} | ||
# Ersetzen Sie 'your_username' und 'your_password' mit Ihren tatsächlichen Anmeldedaten | ||
username = get_nutzername() | ||
auth = HTTPBasicAuth(username, passwort) | ||
|
||
response = requests.get(url, params=params, headers=headers, auth=auth, verify=False) | ||
|
||
if response.status_code == 200: | ||
return response.json() # Gibt das JSON-Antwortobjekt zurück | ||
else: | ||
return f"Error: {response.status_code}" |
6 changes: 6 additions & 0 deletions
6
..._name }}/src/{{ cookiecutter.module_name }}/services/standard/ensure_base_folder_exits.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import os | ||
|
||
def ensure_base_folder_exits(): | ||
base_dir = os.path.join(os.path.expanduser("~"), BASE_DIR) | ||
if not os.path.exists(base_dir): | ||
os.makedirs(base_dir) |
8 changes: 8 additions & 0 deletions
8
....app_name }}/src/{{ cookiecutter.module_name }}/services/standard/ensure_folder_exists.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import os | ||
|
||
def ensure_folder_exists(folder_name): | ||
base_dir = get_base_dir_path() | ||
folder_path = os.path.join(base_dir, folder_name) | ||
if not os.path.exists(folder_path): | ||
os.makedirs(folder_path) | ||
return folder_path |
38 changes: 38 additions & 0 deletions
38
...utter.module_name }}/services/standard/ermittel_den_aktuellen_monat_als_deutsches_wort.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from datetime import datetime | ||
|
||
def ermittel_den_aktuellen_monat_als_deutsches_wort(monat_offset=0): | ||
""" | ||
Ermittelt den Monat relativ zum aktuellen Monat als Zahl und gibt den entsprechenden deutschen Monatsnamen zurück. | ||
Args: | ||
monat_offset (int, optional): Die Anzahl der Monate, die zum aktuellen Monat addiert werden sollen. Standard ist 0. | ||
Returns: | ||
str: Der ermittelte Monat auf Deutsch (z.B. "Januar", "Februar", ...). | ||
""" | ||
# Erstelle ein Dictionary, das die Monatszahlen auf die deutschen Monatsnamen abbildet | ||
monatsnamen = { | ||
1: "Januar", | ||
2: "Februar", | ||
3: "März", | ||
4: "April", | ||
5: "Mai", | ||
6: "Juni", | ||
7: "Juli", | ||
8: "August", | ||
9: "September", | ||
10: "Oktober", | ||
11: "November", | ||
12: "Dezember" | ||
} | ||
|
||
# Ermittle den aktuellen Monat als Zahl | ||
aktueller_monat_als_zahl = datetime.now().month | ||
|
||
# Addiere den Offset zum aktuellen Monat | ||
ziel_monat = (aktueller_monat_als_zahl + monat_offset) % 12 | ||
if ziel_monat == 0: | ||
ziel_monat = 12 | ||
|
||
# Gib den entsprechenden deutschen Monatsnamen zurück | ||
return monatsnamen[ziel_monat] |
97 changes: 97 additions & 0 deletions
97
...r.app_name }}/src/{{ cookiecutter.module_name }}/services/standard/function_extraction.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import os | ||
import ast | ||
from typing import List, Tuple, Set | ||
|
||
|
||
def separate_functions(file_path: str) -> None: | ||
print(f"Processing file: {file_path}") | ||
|
||
with open(file_path, "r") as file: | ||
code = file.read() | ||
|
||
functions = extract_functions(code) | ||
num_functions = len(functions) | ||
print(f"Found {num_functions} functions in the file.") | ||
|
||
directory = os.path.dirname(file_path) | ||
for i, func in enumerate(functions, start=1): | ||
func_name, func_code, func_imports = func | ||
func_file_path = os.path.join(directory, f"{func_name}.py") | ||
|
||
if os.path.exists(func_file_path): | ||
print(f"Skipping function '{func_name}' as the file already exists.") | ||
continue | ||
|
||
print(f"Processing function '{func_name}' ({i}/{num_functions})...") | ||
create_function_file(func_file_path, func_name, func_code, func_imports) | ||
|
||
print("Creating/updating __init__.py file with imports...") | ||
create_init_file(directory, functions) | ||
|
||
print("Done!") | ||
|
||
|
||
def extract_functions(code: str) -> List[Tuple[str, str, Set[str]]]: | ||
tree = ast.parse(code) | ||
functions = [] | ||
imports = extract_imports(code, tree) | ||
|
||
for node in ast.walk(tree): | ||
if isinstance(node, ast.FunctionDef): | ||
func_name = node.name | ||
func_code = ast.get_source_segment(code, node) | ||
func_imports = find_function_imports(node, imports) | ||
functions.append((func_name, func_code, func_imports)) | ||
|
||
return functions | ||
|
||
|
||
def extract_imports(code: str, tree: ast.AST) -> Set[str]: | ||
imports = set() | ||
for node in ast.walk(tree): | ||
if isinstance(node, (ast.Import, ast.ImportFrom)): | ||
import_code = ast.get_source_segment(code, node) | ||
imports.add(import_code) | ||
return imports | ||
|
||
|
||
def find_function_imports(func_node: ast.FunctionDef, imports: Set[str]) -> Set[str]: | ||
func_imports = set() | ||
for node in ast.walk(func_node): | ||
if isinstance(node, ast.Name): | ||
for imp in imports: | ||
if node.id in imp: | ||
func_imports.add(imp) | ||
return func_imports | ||
|
||
|
||
def create_function_file( | ||
file_path: str, func_name: str, func_code: str, func_imports: Set[str] | ||
) -> None: | ||
with open(file_path, "w") as file: | ||
file.write("\n".join(func_imports) + "\n\n" + func_code) | ||
|
||
|
||
def create_init_file( | ||
directory: str, functions: List[Tuple[str, str, Set[str]]] | ||
) -> None: | ||
init_file_path = os.path.join(directory, "__init__.py") | ||
imports = [f"from .{func_name} import {func_name}" for func_name, _, _ in functions] | ||
|
||
if os.path.exists(init_file_path): | ||
with open(init_file_path, "r") as file: | ||
existing_imports = file.readlines() | ||
|
||
# Remove existing imports | ||
imports = [imp for imp in imports if imp not in existing_imports] | ||
|
||
# Combine existing and new imports | ||
imports = existing_imports + imports | ||
|
||
with open(init_file_path, "w") as file: | ||
file.write("\n".join(imports)) | ||
|
||
|
||
if __name__ == "__main__": | ||
file_path = input("Enter the path to the file containing functions: ") | ||
separate_functions(file_path) |
4 changes: 4 additions & 0 deletions
4
...iecutter.app_name }}/src/{{ cookiecutter.module_name }}/services/standard/get_base_dir.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
def get_base_dir(): | ||
return get_base_dir_path() |
10 changes: 10 additions & 0 deletions
10
...name }}/src/{{ cookiecutter.module_name }}/services/standard/get_beweismittel_data_OWi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from requests.auth import HTTPBasicAuth | ||
import platform | ||
from datetime import datetime | ||
import json | ||
|
||
def get_beweismittel_data_OWi(): | ||
ensure_beweismittel_OWi_data_file_exists() | ||
file_path = get_beweismittel_OWi_data_file_path() | ||
with open(file_path, "r") as f: | ||
return json.load(f) |
10 changes: 10 additions & 0 deletions
10
...}/src/{{ cookiecutter.module_name }}/services/standard/get_beweismittel_data_scheidung.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from requests.auth import HTTPBasicAuth | ||
import platform | ||
from datetime import datetime | ||
import json | ||
|
||
def get_beweismittel_data_scheidung(): | ||
ensure_beweismittel_Scheidung_data_file_exists() | ||
file_path = get_beweismittel_Scheidung_data_file_path() | ||
with open(file_path, "r") as f: | ||
return json.load(f) |
Oops, something went wrong.