From 4ede0644b249e53a632129eeb130fa56b5286954 Mon Sep 17 00:00:00 2001 From: loganbates-fc Date: Thu, 3 Feb 2022 11:36:23 -0700 Subject: [PATCH 1/2] added a generic python recipe --- recipes/load_pic.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 recipes/load_pic.py diff --git a/recipes/load_pic.py b/recipes/load_pic.py new file mode 100644 index 0000000..9e526e7 --- /dev/null +++ b/recipes/load_pic.py @@ -0,0 +1,41 @@ +""" Recipe script which uses the FullContact Python library to resolve contact identifiers to personIds. In this case, the input file is presumed to have a header representing a valid Multifield request (https://github.com/fullcontact/fullcontact-python-client#multifieldrequest). + +#!/usr/bin/env python3 +import csv +import os + +from fullcontact import FullContactClient + +# Fetch API Key from env variable "FC_API_KEY" +API_KEY = os.environ.get('FC_API_KEY') + +# Define input, output +input_file = './input.csv' +output_filename= './output.csv' +outputs = [] + +fullcontact_client = FullContactClient(api_key=API_KEY) +with open(input_file, encoding='utf-8') as csvf: + csv_reader = csv.DictReader(csvf) + + for row in csv_reader: + try: + # Pass all row K:V pairings to API. + future = fullcontact_client.identity.resolve_async(**row) + result = future.result() + personIds = result.get_personIds() + row['personIds'] = personIds + except Exception as e: + # Generic exception handling. Should be more granular in a production env + print('something went wrong: ', e) + row['personIds'] = [] + outputs.append(row) + +with open(output_filename, 'w', newline='') as output_file: + # Define header based on one row's keys + keys = outputs[0].keys() + out_writer = csv.DictWriter(output_file, keys) + out_writer.writeheader() + for row in outputs: + out_writer.writerow(row) + From 814eecd3f4f88f2d1c4e9dd202e4fb1908a997ec Mon Sep 17 00:00:00 2001 From: loganbates-fc Date: Thu, 3 Feb 2022 11:42:20 -0700 Subject: [PATCH 2/2] added some more clarity --- recipes/load_pic.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/recipes/load_pic.py b/recipes/load_pic.py index 9e526e7..ca3b791 100644 --- a/recipes/load_pic.py +++ b/recipes/load_pic.py @@ -1,5 +1,8 @@ """ Recipe script which uses the FullContact Python library to resolve contact identifiers to personIds. In this case, the input file is presumed to have a header representing a valid Multifield request (https://github.com/fullcontact/fullcontact-python-client#multifieldrequest). +This script assumes the names of the input and output are "input.csv" and "output.csv", respectively. +""" + #!/usr/bin/env python3 import csv import os @@ -9,7 +12,7 @@ # Fetch API Key from env variable "FC_API_KEY" API_KEY = os.environ.get('FC_API_KEY') -# Define input, output +# Define input, output file names input_file = './input.csv' output_filename= './output.csv' outputs = []