Skip to content

Instantly share code, notes, and snippets.

@chriskinyua
Created April 16, 2020 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriskinyua/5ff8a527b31451ddc7d7cf157c719bba to your computer and use it in GitHub Desktop.
Save chriskinyua/5ff8a527b31451ddc7d7cf157c719bba to your computer and use it in GitHub Desktop.
import os
import csv
from datetime import datetime
import decimal
from decimal import Decimal
data = ''
def calcPrice(data):
ReferenceID = input("Reference ID: ")
clientName = input("Client Name: ")
date = input("Date (format - dd/mm/yyyy): ")
timeFrom = input("From (time in 24hrs e.g 0900): ")
timeTo = input("To (time in 24hrs e.g 1330): ")
dtFrom = datetime.strptime(timeFrom,"%H%M")
dtTo = datetime.strptime(timeTo,"%H%M")
rate = 5
diff = decimal.Decimal((dtTo - dtFrom).total_seconds()) / decimal.Decimal(3600)
diff = round (diff, 2)
price = rate * diff
data = {'ReferenceID': ReferenceID,
'clientName': clientName,
'Date': date,
'From':timeFrom,
'To':timeTo,
'Rate':rate,
'Price':price}
fieldnames = ["ReferenceID","clientName","Date","From","To","Rate","Price"]
with open(r'records21.csv', 'a') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
writer.writerow(data)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment