Looks pretty good to me, I don't think you needed the indents.
At least it ran fine for me once I removed them.
Did some minor tweaks to the code, for example in python:
a = a + b
becomes:
a += b
On the whole a nice script. Good job.
+1
#!/usr/bin/env python
import sys, time
from datetime import datetime
def write_logfile(data):
with open('worklogs.txt', 'a') as textfile:
textfile.write(data)
def new_entry(hours, wage, descr):
now = datetime.now()
if len(str(wage)) == 3:
now1 = 'Wage: %s, hours: %s, Description: %s %s %s/%s/%s'% (wage,hours,descr,now.strftime("%A")[0:3],now.month,now.day,now.year)
write_logfile(now1)
elif len(str(wage)) <= 2:
now1 = 'Wage: 0%s, Hours: %s, Description: %s %s %s/%s/%s'% (wage,hours,descr,now.strftime("%A")[0:3],now.month,now.day,now.year)
write_logfile(now1)
def new_payment(amount):
now = datetime.now()
now2 = str('Payment of %s recieved %s %s/%s/%s')% (amount,now.strftime("%A")[0:3],now.month,now.day,now.year)
write_logfile(now2)
def total_owed():
wages, payments = 0, 0
print "calculating total"
time.sleep(0.75)
for line in open('worklogs.txt'):
if line.startswith("Wage"):
amount = line[6:9]
wages += int(amount)
elif line.startswith("Payment"):
payment = line[11:14]
payments += int(payment)
totalOwed = wages - payments
print "Wages: " + str(wages)
print "payments: " + str(payments)
print "Total owed: " + str(totalOwed)
print "Did you work or recieve a payment today?\n1) Yes\n2) No"
choice1 = raw_input("Choose a menu number: ")
if choice1 == "1":
while True:
print "1) Make a new entry"
print "2) Current amount owed"
print "3) Record payment recieved"
print "4) Quit"
choice = raw_input("Choose a menu number: ")
if choice == "1":
new_hours = raw_input("How many hours did it take? ")
new_wage = raw_input("How much did you make? ")
new_descr = raw_input("What did you do? ")
new_entry(new_hours, new_wage, new_descr)
elif choice == "2":
total_owed()
elif choice == "3":
payment = raw_input("How much were you paid? ")
new_payment(payment)
elif choice == "4":
sys.exit()
else:
print "Invalid entry"
elif choice1 == "2":
now = datetime.now()
now1 = 'OFF %s/%s/%s %s'% (now.month,now.day,now.year,now.strftime("%A")[0:3])
write_logfile(now1)
else:
print "Invalid entry"