Skip to content

Instantly share code, notes, and snippets.

@lukesnow
Created September 30, 2015 02:40
Show Gist options
  • Save lukesnow/bba4d0920fb3386c7e8b to your computer and use it in GitHub Desktop.
Save lukesnow/bba4d0920fb3386c7e8b to your computer and use it in GitHub Desktop.
pointsplus.py
import csv, os
from datetime import date
d = date.today()
#global pointday
#global dailypoints
#global weeklypoints
#global wkcntr
# Assume data is stored in points.dat file.
fl = open('points.txt', 'rb')
r=csv.reader(fl)
dailypoints = int(r.next()[0])
weeklypoints = int(r.next()[0])
wkcntr = int(r.next()[0])
pointday = r.next()[0]
fl.close()
def getpoints():
print "You have " + str(dailypoints) + \
" daily points and " + str(weeklypoints) + \
" weekly points left."
return
# if it is first time using during current script thread, initialize.
if pointday == '0':
dailypoints=int(44)
weeklypoints = int(49)
wkcntr = 7
pointday = date.today()
# if it is same day, don't initialize dailypoints.
if str(pointday) == str(d):
print "day is the same"
pass
else:
#print "day isnt same!"
dailypoints = int(44)
pointday = date.today()
wkcntr -= 1
if wkcntr == 0:
weeklypoints = int(49)
wkcntr = 7
getpoints()
ans = "u"
ans = raw_input("calculate or use? (c or u): ")
if ans == "c":
p = float(raw_input("enter grams of protein: "))
c = float(raw_input("enter grams of carbs: "))
f = float(raw_input("enter grams of fat: "))
b = float(raw_input("enter grams of fiber: "))
points = int(round(0.09*p+0.11*c+0.26*f-.08*b))
ans = "y"
ans = raw_input("That is " + str(points) + " points. Use? (y or n): ")
else:
points = int(round(float(raw_input("enter number of points: "))))
ans = raw_input("That is " + str(points) + " points. Use? (y or n): ")
if ans == "y" or ans == "":
dailypoints = dailypoints - points
if dailypoints < 0:
weeklypoints = weeklypoints + dailypoints
dailypoints = 0
getpoints()
fl = open('points.txt', 'wb')
fl.write(str(dailypoints)); fl.write(os.linesep)
fl.write(str(weeklypoints)); fl.write(os.linesep)
fl.write(str(wkcntr)); fl.write(os.linesep)
fl.write(str(pointday)); fl.write(os.linesep)
fl.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment