Writing the files requires a folder named "taxfiles" to be created prior to running this script. """ from avatax.client import AvataxClient from tax_code_list import sample_codes as tax_codes import os import sys import time import datetime # Creates a client object using dummy company "tugboat" tugboat = AvataxClient(None, None, None, "sandbox") tugboat.add_credentials(os.environ["USERNAME"], os.environ["PASSWORD"]) comp_id = os.environ["COMPANY"] comp_code = tugboat.get_company(comp_id).json()["companyCode"] # get list of all zip codes with address by date address_gen = tugboat.download_tax_rates_by_zip_code( datetime.date.today().isoformat()) # List comprehension to create array of all addresses from generator # slicing only address information address_array = [ item.decode("utf-8").split(",")[:4] for item in address_gen.iter_lines() ][1:] # create variables for analytic data to be sent to analytics = [] analysis = open("./taxfiles/analytics.txt", "a") location_list = [] iter_count = 0
new_client = AvataxClient(None, None, None, "sandbox") new_client.add_credentials(os.environ["USERNAME"], os.environ["PASSWORD"]) # create variables for analytic data to be sent to analytics = [] analysis = open("./taxfiles/analytics.txt", "a") iter_count = 0 total_start_time = time.time() tax_file_list = [] comp_id = os.environ["COMPANY"] # get all the locations belonging to the target company. location_list = new_client.list_locations_by_company( comp_id).json()["value"] # get the company code for the target company. comp_code = new_client.get_company(comp_id).json()["companyCode"] # go through the zip code list and generate an address for entry in location_list: iter_count += 1 duration = 0 loc_id = entry["id"] # set up the model with the tax codes imported on ln 9 tax_model = { "companyCode": comp_code, "responseType": "Json", "taxCodes": tax_codes, # imported from tax_codes file "locationCodes": [entry["locationCode"]] } start = time.time()