473,320 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1227

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
0
by: Karsten Heymann | last post by:
Hello List, Maybe someone can help me with some hobby project... I'm currently searching for a way to convert photos to assci-art files ready to print out, which means to a postscript or pdf...
4
by: Faheem Mitha | last post by:
Dear People, I have the current modest goal. Given a user defined class, I want to creata an array of instances of that class. Consider the following class. class cell: def...
10
by: John Henry | last post by:
Hi all, I have a need to create a Python script on the fly from another Python program and then execute the script so created. Do I need to invoke Python through os.spawnl or is there a better...
267
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at...
3
by: Jack Diederich | last post by:
QOTW: "Because there's no chance that the original request is sane." - Georg Brandl (responding to a question involving a Banana) "this is one of your last chances to test the new code in 2.5...
12
by: kath | last post by:
How do I read an Excel file in Python? I have found a package to read excel file, which can be used on any platform. http://www.lexicon.net/sjmachin/xlrd.htm I installed and working on the...
8
by: bcdonovan | last post by:
Hi everyone, I'm wondering if anyone knows of a way to extract data from a numeric array along a line. I have a gridded dataset which I would like to be able to choose two points and extract a...
19
by: Dongsheng Ruan | last post by:
with a cell class like this: #!/usr/bin/python import sys class Cell: def __init__( self, data, next=None ): self.data = data
4
by: John Nagle | last post by:
I'm printing out each entry in "gc.garbage" after a garbage collection in DEBUG_LEAK mode, and I'm seeing many entries like <cell at 0x00F7C170: function object at 0x00FDD6B0> That's the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.