By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,337 Members | 2,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,337 IT Pros & Developers. It's quick & easy.

Python app to ration cell-phone minutes

P: n/a
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.


$ cat
#!/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,

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 )
print "%d/%d: weekend" % (time.localtime(date)[1],
date += oneDay
Aug 15 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.