All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in -6s
85 lines
2.5 KiB
Python
Executable File
85 lines
2.5 KiB
Python
Executable File
#! /usr/bin/env python3.13
|
|
|
|
import csv
|
|
import os
|
|
from datetime import date
|
|
from datetime import datetime
|
|
|
|
|
|
def check_csv_file_create_new():
|
|
current_month = datetime.now().month
|
|
current_year = datetime.now().year
|
|
csv_file = str(current_year) + "-" + \
|
|
str(current_month) + "-" + "ausgaben.csv"
|
|
return str(csv_file)
|
|
|
|
|
|
# + check_csv_file_create_new())
|
|
default_csv = str("ausgaben_month/" + check_csv_file_create_new())
|
|
|
|
|
|
def create_csv_file(csv_path=default_csv):
|
|
if not os.path.exists(csv_path):
|
|
directory_csv = os.path.dirname(default_csv)
|
|
os.makedirs(directory_csv, exist_ok=True)
|
|
print(csv_path, "wird angelegt !!")
|
|
to_write_header = ["datum", "ausgaben", "beschreibung"]
|
|
with open(csv_path, "w") as wfile:
|
|
writer = csv.writer(wfile)
|
|
writer.writerow(to_write_header)
|
|
return "INFO :", csv_path, "wurde angelegt"
|
|
else:
|
|
return "INFO :", csv_path, "existiert bereits"
|
|
|
|
|
|
def read_csv_file(csv_file=default_csv):
|
|
if os.path.exists(csv_file):
|
|
read_csv_file_ausgabe = []
|
|
|
|
with open(csv_file, "r") as ocsv:
|
|
read_csv_full = csv.DictReader(ocsv)
|
|
for csv_lines in read_csv_full:
|
|
read_csv_file_ausgabe.append(
|
|
{
|
|
"datum": csv_lines["datum"],
|
|
"ausgabe": csv_lines["ausgaben"],
|
|
"beschreibung": csv_lines["beschreibung"],
|
|
}
|
|
)
|
|
return read_csv_file_ausgabe
|
|
else:
|
|
create_csv_file()
|
|
return read_csv_file()
|
|
|
|
|
|
def write_csv_file(
|
|
csv_file=default_csv, date_time=date.today(), betrag=float, select_dist="Essen"
|
|
):
|
|
|
|
import_list = [date_time, betrag, select_dist]
|
|
with open(csv_file, "a") as wfile:
|
|
writer = csv.writer(wfile)
|
|
writer.writerow(import_list)
|
|
|
|
|
|
def sum_all():
|
|
sum_rech = float(0)
|
|
for val_csv in read_csv_file():
|
|
sum_rech = float(sum_rech) + float(val_csv["ausgabe"])
|
|
return round(sum_rech, 2)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
default_csv = "ausgaben_month/ausgaben.csv"
|
|
print(sum_all())
|
|
# Apply multiple filters
|
|
# print(create_csv_file())
|
|
# print(read_csv_file())
|
|
# for i in read_csv_file():
|
|
# query_str = i["datum"][:-3]
|
|
# if query_str == "2025-01":
|
|
# print(i["datum"], " ist in 2025-01")
|
|
# if i["datum"] < date("2025", "01", "01"):
|
|
# print(True)
|
|
# webbrowser.open("file://" + os.path.realpath("ausgabe.html"))
|