Python app to ration cell-phone minutes

S

Shawn Milochik

I wrote a little something so I could check my current minutes used to
see how I was doing for the month. I only get 1,000 minutes, and I
have three phones (two other family members share the plan). This way,
I can (theoretically) know ahead of time if I'm trending towards going
over my plan. By the way, I get free minutes on weekends, so it takes
that into consideration.

Everything is working fine. I'm just posting it in case anyone finds
it interesting or useful, and as always, comments or constructive
criticism are welcome.

Shawn



$ cat cell.py
#!/usr/bin/env python

""" Shows the number of minutes which can be use by the end of each
weekday without going over monthly minute limit. """

import time

#Set some constants
minuteLimit = 1000 #minutes in cell phone plan
oneDay = 60 * 60 * 24 #seconds in one day
cycleBegins = 27 #day of month billing cycle begins

date = time.time()

#Find the date of the first day of the billing cycle.
while time.localtime(date)[2] != cycleBegins:
date -= oneDay

#Initialize the variables, setting them to one if necessary, because
we have to start the loop below at the cycleBegins + 1 to avoid
hitting the test immediately.
daysInCycle = 1
weekdaysInCycle = 0
if time.localtime(date)[6] < 5:
weekdaysInCycle += 1

#Find total days and total weekdays in billing month (for proper
reporting of free weekend minutes)
testDate = date + oneDay

while time.localtime(testDate)[2] != cycleBegins:
if time.localtime(testDate)[6] < 5:
weekdaysInCycle += 1
testDate += oneDay
daysInCycle += 1

#Print number of days in cycle and the report.

print "%d total days and %d weekdays in the cycle." % (daysInCycle,
weekdaysInCycle)

weekdaysElapsed = 0
for daysElapsed in range(daysInCycle + 1)[1:]:
if time.localtime(date)[6] < 5:
weekdaysElapsed += 1
print "%d/%d: %d" % (time.localtime(date)[1],
time.localtime(date)[2], (minuteLimit/weekdaysInCycle) *
weekdaysElapsed )
else:
print "%d/%d: weekend" % (time.localtime(date)[1],
time.localtime(date)[2])
date += oneDay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top