From b0a23cd1bd8bbd21db280e8e19da99b0adc4b414 Mon Sep 17 00:00:00 2001 From: Sateallia Date: Fri, 14 Jun 2024 20:53:40 +0300 Subject: [PATCH] Upload files to "/" --- recurmaid | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ recurmaid.csv | 6 ++++++ 2 files changed, 63 insertions(+) create mode 100644 recurmaid create mode 100644 recurmaid.csv diff --git a/recurmaid b/recurmaid new file mode 100644 index 0000000..c2b6522 --- /dev/null +++ b/recurmaid @@ -0,0 +1,57 @@ +#!/usr/bin/python +import sys +import os +from datetime import datetime +from datetime import timedelta +from dateutil.relativedelta import relativedelta +from operator import itemgetter +import csv + +file_db = os.path.realpath(__file__) + ".csv" + +if not os.path.exists(file_db): + print("Couldn't find '" + file_db + "', exiting.") + sys.exit(0) + +data = list(csv.reader(open(file_db))) #NAME,PRICE[USD/EUR/ETC],DATE_START,PERIOD_RECUR[Y/M/D],CODE_COLOR +today = datetime.today().date() +temp = [] + +for x in data: + name = x[0] + price = "%0.2f" % float(x[1][:-3]) + currency = x[1][-3:] + color = x[4] + date_start = datetime.strptime(x[2], "%Y-%m-%d").date() + + date_next = date_start + delta = (today - date_start).days + period_recur = int(x[3][:-1]) + unit_recur = x[3][-1:] + if unit_recur == "D": + while True: + date_next = date_next + timedelta(days=period_recur) + if date_next >= today: break + elif unit_recur == "M": + while True: + date_next = date_next + relativedelta(months=1) + if date_next >= today: break + elif unit_recur == "Y": + while True: + date_next = date_next + relativedelta(years=1) + if date_next >= today: break + temp.append([str(name), str(price), str(currency), str(color), str((date_next - today).days), str(date_next)]) + +dates = [] +for x in temp: + dates.append(int(x[-2])) + +while True: + smallest = min(dates) + res = min(list(enumerate(dates))[0:], key=itemgetter(1))[0] + print(str(temp[res][0]).ljust(16, " ") + " " + str(temp[res][1]).rjust(8, " ") + " " + str(temp[res][2]) + + "\t#" + str(temp[res][3]) + " NEXT: " + str(temp[res][4]).rjust(4, " ") + " days at " + str(temp[res][5])) + temp.pop(res) + dates.pop(res) + if len(temp) == 0: + break diff --git a/recurmaid.csv b/recurmaid.csv new file mode 100644 index 0000000..649476f --- /dev/null +++ b/recurmaid.csv @@ -0,0 +1,6 @@ +Stream Service 1,17.99EUR,2023-03-21,1M,EE9911 +VPS,5USD,2023-01-16,1M,44BB66 +Domain,10.72USD,2023-08-24,1Y,FF7777 +Cell Phone,10.00EUR,2022-10-13,1M,33CCDD +Stream Service 2,10.00USD,2023-03-22,1M,11BB55 +Bus,30.99USD,2023-04-25,31D,55DDFF