def update_snappy_ticket_with_extras(snappy_api, nonce, contact_key, subject):
    # Short-circuit if there are no extras
    if not settings.SNAPPY_EXTRAS:
        return True
    # Gets more extras from Vumi and creates a private note with them
    contacts_api = ContactsApiClient(auth_token=settings.VUMI_GO_API_TOKEN)
    contact = contacts_api.get_contact(contact_key)
    extra_info = ""
    for extra in settings.SNAPPY_EXTRAS:
        extra_info += extra + ": " + contact["extra"][extra] + "\n"
    if extra_info != "":
        # Send private note
        to_addr = [{
            "name": "Internal Information",
            "address": settings.SNAPPY_EMAIL,
        }]
        snappy_api.create_note(
            mailbox_id=settings.SNAPPY_MAILBOX_ID,
            subject=subject,
            message=extra_info,
            to_addr=to_addr,
            id=nonce,
            scope="private",
            staff_id=settings.SNAPPY_STAFF_ID
        )
    return True
예제 #2
0
def export_contacts(ctx, token, resume, csv, json):
    """ Export contacts from the contacts API.
    """
    if not all((ctx.obj.account_key, token)):
        raise click.UsageError(
            "Please specify both the account key and the contacts API"
            " authentication token. See --help.")
    if not any((csv, json)) or all((csv, json)):
        raise click.UsageError(
            "Please specify either --csv or --json (but not both).")
    contacts_api = ContactsApiClient(token)
    if csv:
        write_contact = csv_contact_writer(csv, resumed=bool(resume))
    else:
        write_contact = json_contact_writer(json)
    try:
        for contact in contacts_api.contacts(start_cursor=resume):
            write_contact(contact)
    except PagedException as err:
        raise click.ClickException(
            "Error downloading contacts. Please re-run with --resume=%s to"
            " resume." % err.cursor)
예제 #3
0
def export_contacts(ctx, token, resume, csv, json):
    """ Export contacts from the contacts API.
    """
    if not all((ctx.obj.account_key, token)):
        raise click.UsageError(
            "Please specify both the account key and the contacts API"
            " authentication token. See --help.")
    if not any((csv, json)) or all((csv, json)):
        raise click.UsageError(
            "Please specify either --csv or --json (but not both).")
    contacts_api = ContactsApiClient(token)
    if csv:
        write_contact = csv_contact_writer(csv, resumed=bool(resume))
    else:
        write_contact = json_contact_writer(json)
    try:
        for contact in contacts_api.contacts(start_cursor=resume):
            write_contact(contact)
    except PagedException as err:
        raise click.ClickException(
            "Error downloading contacts. Please re-run with --resume=%s to"
            " resume."
            % err.cursor)
def update_snappy_ticket_with_extras(snappy_api, nonce, contact_key, subject):
    # Short-circuit if there are no extras
    if not settings.SNAPPY_EXTRAS:
        return True
    # Gets more extras from Vumi and creates a private note with them
    contacts_api = ContactsApiClient(auth_token=settings.VUMI_GO_API_TOKEN)
    contact = contacts_api.get_contact(contact_key)
    extra_info = ""
    for extra in settings.SNAPPY_EXTRAS:
        extra_info += extra + ": " + contact["extra"][extra] + "\n"
    if extra_info != "":
        # Send private note
        to_addr = [{
            "name": "Internal Information",
            "address": settings.SNAPPY_EMAIL,
        }]
        snappy_api.create_note(mailbox_id=settings.SNAPPY_MAILBOX_ID,
                               subject=subject,
                               message=extra_info,
                               to_addr=to_addr,
                               id=nonce,
                               scope="private",
                               staff_id=settings.SNAPPY_STAFF_ID)
    return True
import logging
import json

from go_http.contacts import ContactsApiClient
import app_settings as settings

logging.basicConfig(
    filename=settings.LOG_FILE, level=settings.LOGGING_LEVEL)

DELETE_CONTACTS = False

try:
    api = ContactsApiClient(settings.AUTH_TOKEN, settings.API_URL)
    logging.info('Created API successfully')
except Exception as e:
    logging.error('Error creating API')
    logging.debug('API error: %s' % e.message)
    raise e


def get_keys(items):
    keys = []
    for item in items:
        key = item.get('key', None)
        if key is not None:
            keys.append(key)
    return keys

with open(settings.PROCESSED_CONTACTS_FILENAME, 'r') as processed:
    for item in processed:
        item = json.loads(item)
parser.add_argument(
    'filename', metavar='filename', type=str, nargs=1,
    help='Filename to find the duplicate contact results.')
args = parser.parse_args()


def get_keys(items):
    keys = []
    for item in items:
        key = item.get('key', None)
        if key is not None:
            keys.append(key)
    return keys

try:
    api = ContactsApiClient(settings.AUTH_TOKEN, settings.API_URL)
    logging.info('Created API successfully')
except Exception as e:
    logging.error('Error creating API')
    logging.debug('API error: %s' % e.message)
    raise e

with open(args.filename[0], 'r') as processed:
    for item in processed:
        item = json.loads(item)
        new_contact = item.get('new_contact')
        old_contacts = item.get('old_contacts')
        old_keys = get_keys(old_contacts)
        try:
            api.create_contact(new_contact)
            logging.info(
import logging
import json

from go_http.contacts import ContactsApiClient
import app_settings as settings

logging.basicConfig(filename=settings.LOG_FILE, level=settings.LOGGING_LEVEL)

DELETE_CONTACTS = False

try:
    api = ContactsApiClient(settings.AUTH_TOKEN, settings.API_URL)
    logging.info('Created API successfully')
except Exception as e:
    logging.error('Error creating API')
    logging.debug('API error: %s' % e.message)
    raise e


def get_keys(items):
    keys = []
    for item in items:
        key = item.get('key', None)
        if key is not None:
            keys.append(key)
    return keys


with open(settings.PROCESSED_CONTACTS_FILENAME, 'r') as processed:
    for item in processed:
        item = json.loads(item)
logging.basicConfig(
    filename=settings.LOG_FILE, level=settings.LOGGING_LEVEL)

parser = argparse.ArgumentParser(description="Download contacts")
parser.add_argument(
    'filename', type=str, nargs=1,
    help='Filename to store the downloaded contacts in.')
parser.add_argument(
    '--append', '-a', dest='file_mode', default='w', action='store_const',
    const='a', help='Append downloaded contacts to the file instead of the' +
    ' default overwrite')
args = parser.parse_args()

try:
    api = ContactsApiClient(settings.AUTH_TOKEN, settings.API_URL)
    logging.info('Created API successfully')
except Exception as e:
    logging.error('Error creating API')
    logging.debug('API error: %s' % e.message)
    raise e

f = None
try:
    f = open(args.filename[0], args.file_mode)
except Exception as e:
    logging.error('Error creating file')
    logging.debug('File error: %s' % e.message)
    raise e

for contact in api.contacts():
예제 #9
0
 def make_client(self, auth_token=AUTH_TOKEN):
     return ContactsApiClient(auth_token,
                              api_url=self.API_URL,
                              session=self.session)
예제 #10
0
 def test_default_api_url(self):
     contacts = ContactsApiClient(self.AUTH_TOKEN)
     self.assertEqual(contacts.api_url, "https://go.vumi.org/api/v1/go")
예제 #11
0
 def test_default_session(self):
     import requests
     contacts = ContactsApiClient(self.AUTH_TOKEN)
     self.assertTrue(isinstance(contacts.session, requests.Session))