473,569 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(daysInCyc le + 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 1239

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

Similar topics

13
35509
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 and extract information from specific worksheets and cells. I'm not really sure how to get started with this process. I ran the COM Makepy...
0
1255
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 file, which contains many many letters in some non-proportional font which together look like the photo. Currently I'm using gimp (for looking up...
4
3658
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 setrow(self,row): self.row = row
10
2194
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 way? Thanks, -- John
267
10578
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 http://www.artima.com/weblogs/viewpost.jsp?thread=147358
3
239
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 before the final release. *Please* try this release out and let us know about any problems you find" - Anthony Baxter, Python Release Manager ...
12
6004
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 examples, I found its printing of cell's contents in a different manner. print sh.row(rx)
8
1832
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 1-d array of the data values along the line between the two points. Any ideas? Thanks, Brian
19
7808
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
2845
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 output of "repr". Are "cell" objects created only from external C libraries, or can regular Python code generate them? Is there any way to find out...
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.