Skip to content

Instantly share code, notes, and snippets.

@rdegges
Created January 16, 2010 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdegges/278769 to your computer and use it in GitHub Desktop.
Save rdegges/278769 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
"""
pyannoy.py
@author: Randall Degges
@email: rdegges@gmail.com
@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 program allows users
to annoy a friend by calling them a specified amount of times, and playing a soundfile.
"""
from os import path
from sys import argv, exit
from datetime import datetime
from random import seed, randint
from pycall.callfile import *
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]
# Create the reusable CallFile object.
cf = CallFile(
trunk_type = 'SIP',
trunk_name = 'flowroute',
number = argv[1],
application = 'Playback',
data = soundfile,
user = 'asterisk' # Change this to whatever user Asterisk runs as.
)
# 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.
cf.callerid_num = cid
cf.run(time)
# 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