import time, argparse, re, unidecode, sys, json from progressbar import ProgressBar from progressbar.widgets import Percentage, Bar, ETA, FileTransferSpeed from requests.exceptions import ConnectionError from closeio_api import Client as CloseIO_API from closeio_api.utils import CsvReader, count_lines, title_case, uncamel parser = argparse.ArgumentParser(description='Import leads from CSV file') parser.add_argument('--api_key', '-k', required=True, help='API Key') parser.add_argument('--skip_duplicates', action='store_true', help='Skip leads that are already present in Close.io (determined by company name).') parser.add_argument('--no_grouping', action='store_true', help='Turn off the default group-by-company behavior.') parser.add_argument('--development', action='store_true', help='Use a development server rather than production.') parser.add_argument('file', help='Path to the csv file') args = parser.parse_args() reader = CsvReader(args.file) header = reader.next() # skip the 1st line header import_count = count_lines(args.file) # may have no trailing newline cnt = success_cnt = 0 def slugify(str, separator='_'): str = unidecode.unidecode(str).lower().strip() return re.sub(r'\W+', separator, str).strip(separator) # Look for headers/columns that match these, case-insensitive. All other headers will be treated as custom fields. expected_headers = ( 'company', # multiple contacts will be grouped if company names match 'url',