471,354 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Python app to ration cell-phone minutes

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
Aug 15 '07 #1
0 1146

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Allison Bailey | last post: by
reply views Thread by Karsten Heymann | last post: by
4 posts views Thread by Faheem Mitha | last post: by
10 posts views Thread by John Henry | last post: by
267 posts views Thread by Xah Lee | last post: by
12 posts views Thread by kath | last post: by
8 posts views Thread by bcdonovan | last post: by
19 posts views Thread by Dongsheng Ruan | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.