Esempio n. 1
0
def error_handler():
    "main error handler function"
    try:
        body = create_body()
        mail = create_message(body, SUBJECT, "*****@*****.**")
        send_mail(mail, "*****@*****.**")
    except:
        error_message = traceback.format_exc()
        log(error_message)
Esempio n. 2
0
def process_user( user, utas, database, smtpserver ):
    'process one user'
    try:
        uta          = utas[ user[ 'send_index' ] ]
        mail_address = user[ 'mail_address' ]
        subject      = create_subject( uta )
        body         = create_body( user[ 'direction' ], uta,
                                    user[ 'column' ], user[ 'row' ] )
        mail         = create_message( body, subject, mail_address )
        if send_mail( mail, mail_address, smtpserver ):
            increment_send_index( database, mail_address )
    except:
        error_handler()
Esempio n. 3
0
        for j in range(num_users):
            if mapping[i][j] == 0:
                potential_receiver_indexes.append(j)
        if len(potential_receiver_indexes) == 0:
            found_issue = True
            break  # solution not found, no more receivers possible
        to_give_index = random.choice(potential_receiver_indexes)
        mapping[i][to_give_index] = 1  # give to this user!!
        mapping[to_give_index][
            i] = -1  # this user should not give anything back!
        for k in range(num_users):
            if k != i:
                mapping[k][
                    to_give_index] = -1  # This user should not receive from anyone else
    if not found_issue:
        # SOLUTION FOUND!!!
        found_solution = True
        break
if not found_solution:
    raise RuntimeError("Could not found the solution but tried really hard.")
else:
    # print mapping
    for i in range(num_users):
        user_name = user_names[i]
        user_email = users[user_names[i]]['email']
        to_give_index = mapping[i].index(1)
        to_give_username = user_names[to_give_index]
        # print "{0} should give {1} a present!".format(user_name, to_give_username)
        email_message = create_message(user_email, user_name, to_give_username)
        send_mail(user_email, email_message)
    close_mail_server()