Skip to content

Commit 65825a9

Browse files
authored
Add support for multiple fob fields, and CSV fob fields (#5)
* Add support for multiple fob fields, and CSV fob fields * fobs is always defined
1 parent 531638e commit 65825a9

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

main.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
TIMEZONE = tz.gettz("America/New_York")
3131
NEON_ORG_ID = "decaturmakers"
32-
NEON_FIELD_NAME_FOB = "Fob10Digit"
32+
NEON_FIELD_NAMES_FOB = ["Fob10Digit", "FobCSV"]
3333
NEON_FIELD_NAME_DM_MEMBERS = "Added to dm-members"
3434
NEON_FIELD_NAME_CHECKR = "Invited to Checkr"
3535
CHECKR_WORK_LOCATIONS = [
@@ -106,7 +106,7 @@ class User(NamedTuple):
106106
account_id: str
107107
name: str
108108
email: Optional[str]
109-
fob: Optional[str]
109+
fobs: List[str]
110110
zones: frozenset[str]
111111
is_membership_expired: bool
112112
added_to_dm_members: bool
@@ -127,6 +127,7 @@ def can_access(neon_result: Dict[str, str], zone: str) -> bool:
127127
return False
128128
return all(neon_result.get(field) for field in ZONE_REQUIREMENTS[zone])
129129

130+
130131
def check_res(res: requests.Response):
131132
try:
132133
res.raise_for_status()
@@ -135,6 +136,7 @@ def check_res(res: requests.Response):
135136
logging.warning(res.text)
136137
raise
137138

139+
138140
class NeonOption(NamedTuple):
139141
"""One possible value of a "custom field" in NeonCRM"""
140142

@@ -380,11 +382,17 @@ def get_page(page: int) -> Tuple[int, List[Dict[str, Any]]]:
380382
)
381383
else:
382384
is_minor = None # unknown whether user is a minor
385+
fobs: List[str] = []
386+
for fieldname in NEON_FIELD_NAMES_FOB:
387+
fobs.extend([
388+
x.strip() for x in result.get(fieldname, "").split(",")
389+
if x != ""
390+
])
383391
yield User(
384392
account_id=result["Account ID"],
385393
name=result["Full Name (F)"],
386394
email=result["Email 1"] or None,
387-
fob=result.get(NEON_FIELD_NAME_FOB),
395+
fobs=fobs,
388396
zones=zones,
389397
is_membership_expired=expired,
390398
is_minor=is_minor,
@@ -415,8 +423,9 @@ def update_users() -> None:
415423
for user in users:
416424
if user.email is not None:
417425
new_users_by_email[user.email] = user
418-
if user.fob is not None:
419-
new_users_by_fob[user.fob] = user
426+
if user.fobs:
427+
for fob in user.fobs:
428+
new_users_by_fob[fob] = user
420429
if (
421430
not user.invited_to_checkr
422431
and user.email is not None

0 commit comments

Comments
 (0)