import re


def unsubscribe_user(cur, phone, confcode):
    """
    Adds a user to the unsubscribe table

    Params:
        cur: (psycopg2.extensions.cursor) A Cursor to the database
        phone: (str) phone number in E.164 format
        confcode: (int) randome 128-bit code

    Returns:
        (str) a response message to the user to be flashed on the webpage
    """
    assert re.match('\+\d{9}', phone), "Invalid phone number format: %r" % phone
    assert type(confcode) == int, "Invalid confirmation code: %r" % confcode
    print((phone, confcode))
    cur.execute("INSERT INTO unsubscribe (phone, confcode) VALUES (%s, %s);", [phone, confcode])

    return 'Unsubscribe requested for %s. You should receive a text message shortly to confirm unsubscribe' % (phone)