Ejemplo n.º 1
0
def list_donors():
    try:
        r = login_db.login_redis_cloud()
        for i in r.keys():
            print(i)
    except Exception as e:
        print(f'Redis error: {e}')
Ejemplo n.º 2
0
def send_thankyou():
    don_input = None
    while not don_input:
        don_input = donor_input()
        if don_input.lower() == "list":
            list_donors()
            don_input = None

    donation = None
    while not donation:
        try:
            donation = int(donation_prompt())
        except ValueError:
            print("Enter a monetary donation.")
    phone = input('Enter phone number (nnn-nnn-nnnn: ')
    zip = input('Enter zip code (nnnnn): ')
    email = input('Enter email address: ')
    try:
        r = login_db.login_redis_cloud()
        r.hmset(don_input, {
            'phone': phone,
            'zip': zip,
            'donation': [donation],
            'email': email
        })
    except:
        print("There was an error adding donor to database.")

    print("Thank you {} for your donation of ${}.".format(don_input, donation))
Ejemplo n.º 3
0
def delete_donor():
    name = input('Enter name to delete from database: ')
    r = login_db.login_redis_cloud()
    if r.exists(name):
        r.delete(name)
    else:
        print('{} is not in the database.'.format(name))
Ejemplo n.º 4
0
def run_example():
    """
        Redis

    """

    log = utilities.configure_logger('default', '../logs/redis_script.log')

    try:
        log.info('Step 1: connect to Redis')
        r = login_db.login_redis_cloud()
        log.info('Step 2: cache data in db')
        r.set('natalie', '*****@*****.**')

        log.info('Step 2: Add some data to the cache')
        r.hmset('Luke', {'phone': '319-706-8805', 'age': 29})
        r.hmset('Virgil', {'phone': '913-366-2202', 'age': 15})
        r.hmset('River', {'phone': '972-310-1058', 'age': 36})
        r.hmset('Kibson', {'phone': '309-304-0112', 'age': 5})

        log.info('Step 3: Return Virgil\'s phone number')
        phone_virgil = r.hmget('Virgil', 'phone')
        log.info(f'Virgil\'s phone number: {phone_virgil}')

        log.info('Step 4: Get Virgil\'s')
        age_virgil = r.hmget('Virgil', 'age')
        log.info(f'Virgil\'s age: {age_Virgil}')

    except Exception as e:
        print(f'Redis error: {e}')
Ejemplo n.º 5
0
def lookup_email():
    donor = input('Enter Donor Name to find their email address.\n')
    try:
        r = login_db.login_redis_cloud()
        if r.exists(donor):
            print('{}\'s email is: {}'.format(donor, r.hget(donor, 'email')))
        else:
            print('{} is not in the database.'.format(donor))
    except Exception as e:
        print(f'Redis error: {e}')
Ejemplo n.º 6
0
def create_report():
    print('{:20} | {:20} | {:20} | {:20}'.format('Donor Name', 'Donations',
                                                 'Phone No.', 'Email'))
    print('-' * 80)
    try:
        r = login_db.login_redis_cloud()
        for i in r.keys():
            print('{:20} | {:20} | {:20} | {:20}'.format(
                i, r.hget(i, 'donation'), r.hget(i, 'phone'),
                r.hget(i, 'email')))
    except Exception as e:
        print(f'Redis error: {e}')
Ejemplo n.º 7
0
def run_example():
    """
        non-presistent Redis
    """

    log = utilities.configure_logger('default', '../logs/redis_script.log')

    try:
        log.info('Step 1: connect to Redis.')
        r = login_db.login_redis_cloud()

        log.info('Step 2: Add donor data to cache.')
        r.hmset(
            'Luke Rodriguez', {
                'phone': '319-706-8805',
                'zip': 60012,
                'donation': [45, 76, 100],
                'email': '*****@*****.**'
            })
        r.hmset(
            'Virgil Ferdinand', {
                'phone': '913-366-2202',
                'zip': 75019,
                'donation': [3500, 50],
                'email': '*****@*****.**'
            })
        r.hmset(
            'River Tails', {
                'phone': '972-310-1058',
                'zip': 61761,
                'donation': [4000],
                'email': '*****@*****.**'
            })
        r.hmset(
            'Joseph Kibson', {
                'phone': '309-304-0112',
                'zip': 61704,
                'donation': [12, 25, 350, 450],
                'email': '*****@*****.**'
            })
        r.hmset(
            'Emily Connor', {
                'phone': '387-696-2058',
                'zip': 43055,
                'donation': [20],
                'email': '*****@*****.**'
            })

    except Exception as e:
        print(f'Redis error: {e}')
Ejemplo n.º 8
0
def send_letters():
    r = login_db.login_redis_cloud()
    for i in r.keys():
        with open('{}.txt'.format(i), 'w') as donorfh:
            donorfh.write(send_thankyou_total(i, r.hget(i, 'donation')))