def say_digits(number):
    """
    10/04/09: called by read_back_caller_number().
    says the phone numbers
    """

    dsh_common_db.init_log(quiet=True)
    funcName = 'dsh_common_agi.say_digits:'
    number = number.strip()

    soundDir = dsh_common_config.lookup('DSH_PROMPT_DIR')
    sorrySound = dsh_config.lookup('DSH_PROMPT_SORRY')
    sorrySound = os.path.join(soundDir, sorrySound)
    
    if not number:
        dsh_agi.say_it(sorrySound)
        return

    try:
        inumber = int(number)
    except:
        message = '%s not a number: %s.' % (funcName, number)
        dsh_agi.report_event(message, reportLevel='ERR')
        dsh_utils.give_bad_news(message, logging.error)
        dsh_agi.say_it(sorrySound)
        return

    datesDir = os.path.join(soundDir, 'dates')
    dateDir = os.path.join(datesDir, 'dates')

    for digit in number:
        digit = '0' + digit
        sound = os.path.join(dateDir, digit)
        dsh_agi.say_it(sound)
def say_date(item):
    """called by dsh_django2.test_call_say_time(), and
    dsh_django2.say_person_name().
    """

    time = item.modify_datetime
    
    soundDir = dsh_common_config.lookup('DSH_PROMPT_DIR')
    datesDir = os.path.join(soundDir, 'dates')
    
    thisMessage = os.path.join(datesDir, 'this_message')
    wasRecorded = os.path.join(datesDir, 'was_recorded')
    
    dateDir = os.path.join(datesDir, 'dates')
    monthDir = os.path.join(datesDir, 'months')
    yearDir = os.path.join(datesDir, 'year')

    yStr = time.strftime('%#y')
    mStr = time.strftime('%#m')
    dStr = time.strftime('%#d')

    testDate = os.path.join(dateDir, dStr)
    testMonth = os.path.join(monthDir, mStr)
    testY2k = os.path.join(yearDir, '2000')
    testYear = os.path.join(dateDir, yStr)

    dsh_agi.say_it(thisMessage)
    dsh_agi.say_it(testDate)
    dsh_agi.say_it(testMonth)
    dsh_agi.say_it(testY2k)
    dsh_agi.say_it(testYear)
    dsh_agi.say_it(wasRecorded)
def demo_reply_prompt_confirm(recent, itemTable, keyWordTable, eventTable,
                              sessionID=''):
    """
    10/04/09: called by demo_reply().
    modeled after dsh_django2.handle_staff_caller().
    """

    funcName = 'dsh_common_agi.demo_reply_prompt_confirm:'
    count = 0
    promptDir = dsh_common_config.lookup('DSH_PROMPT_DIR')
    demoPress1 = dsh_common_config.lookup('DSH_PROMPT_DEMO_PRESS1_SEND')
    demoPress1 = os.path.join(promptDir, demoPress1)
    timeOut1 = dsh_config.lookup('DSH_PROMPT_WAIT1')
    maxRetries = dsh_common_config.lookup2('STAFF_RETRIES')
    demoSending = dsh_common_config.lookup('DSH_PROMPT_DEMO_SENDING_IN8')
    demoSending = os.path.join(promptDir, demoSending)

    while True:
        count += 1

        if count > maxRetries:
            say_goodbye()
            return True

        choice = dsh_agi.get_digits(demoPress1, 1, timeOut=timeOut1)
        dsh_utils.db_print('%s the choice is: %s.' % (funcName, repr(choice)),
                           168)

        if choice == None or choice == '' or choice == '*':
            say_goodbye()
            return True

        if choice == '1':
            dsh_common_db.attempt_demo_reply_now(
                recent, itemTable, keyWordTable, eventTable,
                sessionID=sessionID)
            dsh_agi.say_it(demoSending)
            say_goodbye()
            return True

        continue

    return True
def read_back_caller_number(item, fromPhone=False, sessionID=''):
    """
    10/04/09: called by demo_reply().  read back the phone number of the
    most recent caller.
    """

    response = ''
    funcName = 'dsh_common_agi.read_back_caller_number:'
    
    caller = item.owner
    phoneNumber = caller.phone_number

    if not phoneNumber:
        message = '%s no phone number: %s.' % (funcName, caller.dsh_uid)
        response += dsh_utils.red_error_break_msg(message)
        dsh_agi.report_event(message, reportLevel='ERR', sessionID=sessionID)
        dsh_utils.give_bad_news(message, logging.error)
        return (False, response)

    message = 'Send an immediate reply to %s @ %s? ' %\
              (caller.__unicode__(), phoneNumber)
    message += '<a href="/senddemoreplyconfirmed/%s">Confirm</a>?' %\
               (item.dsh_uid,)
    response += dsh_utils.black_break_msg(message)

    if fromPhone:
        promptDir = dsh_common_config.lookup('DSH_PROMPT_DIR')
        last4 = dsh_common_config.lookup('DSH_PROMPT_DEMO_LAST4')
        dsh_agi.say_it(os.path.join(promptDir, last4))
        howManyDigits = dsh_config.lookup('HIDE_PHONE_DIGITS')
        lastDigits = phoneNumber[-howManyDigits:]
        dsh_utils.give_news(
            'demo to phone: %s, last 4 digits: %s.' %\
            (phoneNumber, lastDigits), logging.info)
        say_digits(lastDigits)

    return (True, response)
def auto_schedule_delete_all(force=False, sessionID=None):
    """
    moved from dsh_django_utils.py
    called by views.schedule_del_all().
    force=True when initiated by views.schedule_delete_all().
    """

    disableWipe = dsh_db_config.get('reschedule_wipe_disable')
    if not force and disableWipe:
        message = 'dsh_common_agi.auto_schedule_delete_all: ' +\
                  'note: wiping of existing schedule is disabled.'
        dsh_agi.report_event(message, sessionID=sessionID)
        return dsh_utils.black_break_msg(message)

    spoolDir = dsh_common_config.lookup('ASTERISK_DOT_CALL_DIR')
    if not dsh_utils.is_valid_dir(spoolDir, silence=True):
        message = 'dsh_common_agi.auto_schedule_delete_all: ' + \
                  'spool directory invalid: ' + spoolDir
        dsh_agi.report_event(message, reportLevel = 'CRT', sessionID=sessionID)
        return dsh_utils.red_error_break_msg(message)
    
    message = 'dsh_common_agi.auto_schedule_delete_all: ' +\
              'listdir() failed: ' + spoolDir
    try:
        listing = os.listdir(spoolDir)
        listing = dsh_common_db.filter_listdir_with_dbname(listing)
    except:
        dsh_agi.report_event(message, reportLevel = 'CRT', sessionID=sessionID)
        return dsh_utils.red_error_break_msg(message)

    message = dsh_utils.black_break_msg('deleting...')
    
    for one in listing:
        full = os.path.join(spoolDir, one)
        if not one:
            continue
        if os.path.isdir(full):
            continue
        if not dsh_utils.is_valid_file(full):
            continue
        if not one.endswith('.call'):
            continue

        dsh_utils.cleanup_path(
            full, 'dsh_common_agi.auto_schedule_delete_all: ')
        message += dsh_utils.black_break_msg(full)

    message += dsh_utils.black_break_msg('done.')
    return message
import logging,sys,re,time,random,os,os.path
import dsh_common_config,dsh_common_utils,dsh_common_agi

dsh_common_utils.add_to_sys_path(dsh_common_config.lookup('django_sys_paths'))
__import__(dsh_common_config.lookup('APP_NAME_MODELS'))
import dsh_agi,dsh_config,dsh_utils,dsh_django2
import dsh_common_agi, dsh_common_db
os.environ['DJANGO_SETTINGS_MODULE'] = dsh_common_config.lookup(
    'DJANGO_SETTINGS_MODULE')



def test_call_say_time(caller):
    """called by handler_staff_caller().
    test spoken dates.
    """

    dsh_utils.db_print('test_call: entered...', 134)
    answer = dsh_django2.get_outgoing_voice_from_db(caller)
    if not answer:
        dsh_utils.give_bad_news(
            'test_call: get_outgoing_voice_from_db() failed.',
            logging.critical)
        return False
    outVobj,outgoingVoice,allSharedHeard,playShared = answer
    dsh_utils.db_print('test_call: outgoingVoice: ' + outgoingVoice, 134)
    time = outVobj.modify_datetime
    timeStr = time.strftime('%#Y-%#m-%#d')
    dsh_utils.db_print('test_call: timeStr: ' + timeStr, 134)
    dsh_common_agi.say_date(outVobj)
    return True