summaryrefslogtreecommitdiff
path: root/app/income/parser.py
blob: b19d0393a97d26e7cda7f89f46582baa7cbd4be4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import csv
import datetime
from .models import InvoiceItem


def read_timesheet():
    with open('timesheet.csv', newline='') as csvfile:
        reader = csv.reader(csvfile, delimiter=';')
        counter = 0
        f = "%Y-%m-%d %H:%M:%S"
        for row in reader:
            if counter > 0:
                print(row[4])
                timer = row[0]+' '+row[1]
                timerer = row[0]+' '+row[2]
                time_start = datetime.datetime.strptime(timer, f)
                time_end = datetime.datetime.strptime(timerer, f)
                InvoiceItem.objects.get_or_create(
                    time_start=time_start,
                    time_end=time_end,
                    work_done=row[4]
                )
            counter = counter + 1