Skip to content

Instantly share code, notes, and snippets.

@rdegges
Created January 16, 2010 06:27
Show Gist options
  • Save rdegges/278691 to your computer and use it in GitHub Desktop.
Save rdegges/278691 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
"""
pyannoy-skeleton.py
@author: Randall Degges
@email: [email protected]
@date: 1-15-2010
@license: GPLv3 (http://www.gnu.org/licenses/gpl-3.0.txt)
This program is part of the 'pyannoy' program used in the pycall getting started tutorial.
This tutorial can be found at: http://pycall.org/getting-started/. This skeleton program
only outlines the annoy program, and doesn't actually place any calls or use pycall.
"""
from os import path
from sys import argv, exit
from datetime import datetime
from random import seed, randint
def gen_random_cid():
"""
Generate a random US (NANPA) caller ID. Not perfect, but good enough for this program.
"""
return randint(12112111111, 19999999999)
def validate_args():
"""
Validate all command line arguments, and give proper errors if required.
"""
# Make sure that the required parameters are specified, and that they are numeric.
if len(argv) < 3 or not argv[1].isdigit() or not argv[2].isdigit():
print 'Usage: %s person-to-annoy amount-of-times-to-call [soundfile-to-play]' % argv[0]
exit(1)
# If the optional parameter was specified (soundfile), make sure that it exists.
if len(argv) == 4 and not path.isfile(argv[3]):
print 'Error: Soundfile %s does not exist, or is not a file.' % argv[3]
exit(1)
def main():
"""
Annoy a person.
"""
seed() # Seed the random number generator.
validate_args()
time = datetime.now() # Get the current time.
# If the user didn't specify the third (optional) command line parameter, then play the
# hello-world soundfile which is included with every Asterisk installation.
if len(argv) == 3:
soundfile = 'hello-world'
else:
soundfile = argv[3]
# Place a series of calls, each with a random caller ID. Each call is placed exactly 1
# minute after the previous.
for x in xrange(int(argv[2])):
# Generate a random caller ID.
cid = gen_random_cid()
print 'Placing call... %d to %d using caller ID %d and playing soundfile %s at %s' % (x, int(argv[1]), cid, soundfile, time)
# Make the call here.
# Move the time forward a minute.
time = datetime(time.year, time.month, time.day, time.hour, time.minute+1, time.second)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment