2024-12-15 15:11:11 -06:00

61 lines
1.4 KiB
Python
Executable File

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2024 Jacob Babor <jacob@babor.tech>
#
# Distributed under terms of the MIT license.
from csv import DictReader
import datetime
import glob
import re
import requests
import textwrap
# Config globals
rate = float(41.00)
timesheet = {}
# First, acquire a CSV to look at
csv = glob.glob('*.csv')
if not csv:
print('No csv found!')
quit()
# Then, open that CSV and collect its data, storing it in timesheet
with open(csv[0], 'r') as csv:
items = DictReader(csv)
for row in items:
issue = row["Issue Key"]
date = datetime.datetime.strptime(row["Work date"], '%Y-%m-%d %H:%M').strftime('%Y-%m-%d')
hours = float(row["Hours"])
if not date in timesheet.keys():
timesheet[date] = {}
if not issue in timesheet[date].keys():
timesheet[date][issue] = 0
timesheet[date][issue] += hours
# Next, construct args for the request we'll make to invoice-generator.com's API
requestbody = {
"from": "JACOB",
"to": "CLIENT",
"number": 9999,
"date": "CURRENT_DATE",
"due_date": "DUE_DATE",
"terms": "Net 14 days",
"items": []
}
for k,v in timesheet.items():
print(k)
for i,h in v.items():
requestbody["items"] += {
"name": f""
}
print(f'{ i } - { h }')
# Submit said request