Skip to content

Commit c5e041d

Browse files
Update connector.py
with suggested changes
1 parent 8788208 commit c5e041d

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

examples/source_examples/mastertax/connector.py

+11-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from time import sleep
1414
import requests as rq
1515
import traceback
16-
import datetime
1716
import time
1817
import os
1918
import json
@@ -31,6 +30,9 @@
3130
cert_path = "SSL.crt"
3231
key_path = "SSL_auth.key"
3332

33+
retry_wait_seconds = 300
34+
max_retries = 3
35+
3436
def schema(configuration: dict):
3537
"""
3638
# Define the schema function which lets you configure the schema your connector delivers.
@@ -51,11 +53,8 @@ def update(configuration: dict, state: dict):
5153
try:
5254
token_header = make_headers(configuration)
5355

54-
for e in data_extracts:
55-
yield from sync_items(configuration, token_header, e)
56-
57-
# Yield a checkpoint operation to save the new state.
58-
yield op.checkpoint({})
56+
for extract in data_extracts:
57+
yield from sync_items(configuration, token_header, extract)
5958

6059
except Exception as e:
6160
# Return error response
@@ -107,11 +106,11 @@ def sync_items(configuration: dict, headers: dict, extract: dict):
107106
if tag.get("tagCode") == "LAYOUT_NAME"),
108107
None # Default if not found
109108
)
110-
matching_files = [fn for fn in os.listdir(extract_path) if layout_name in fn]
109+
matching_files = [filename for filename in os.listdir(extract_path) if layout_name in filename]
111110

112-
for m in matching_files:
113-
log.fine(f"processing {m}")
114-
yield from upsert_rows(f"{extract_path}{m}", layout_name)
111+
for file in matching_files:
112+
log.fine(f"processing {file}")
113+
yield from upsert_rows(f"{extract_path}{file}", layout_name)
115114

116115
yield op.checkpoint({})
117116

@@ -123,13 +122,13 @@ def upsert_rows(filename: str, layout_name: str):
123122
:return:
124123
"""
125124

126-
colnames = column_names[layout_name]
125+
layout_column_names = column_names[layout_name]
127126
log.fine(f"upserting rows for {filename}")
128127
with open(filename, "r", newline="", encoding="utf-8") as file:
129128
reader = csv.reader(file, delimiter="\t") # Tab-delimited
130129

131130
for row in reader:
132-
yield op.upsert(table=layout_name, data=dict(zip(colnames, row)))
131+
yield op.upsert(table=layout_name, data=dict(zip(layout_column_names, row)))
133132

134133
def submit_process(url: str, headers: dict, payload: dict):
135134
"""
@@ -139,9 +138,6 @@ def submit_process(url: str, headers: dict, payload: dict):
139138
:param payload: A dictionary with parameters for the extract to submit
140139
:return: status and resource_id
141140
"""
142-
retry_wait_seconds = 300
143-
max_retries = 3
144-
145141
for attempt in range(max_retries + 1):
146142
response = rq.post(url, headers=headers, data=json.dumps(payload), cert=(cert_path, key_path))
147143

0 commit comments

Comments
 (0)