Work on badge importing

This commit is contained in:
Scott Idem
2022-03-21 17:59:05 -04:00
parent 88e5daebfa
commit e1eeb8990c
3 changed files with 60 additions and 6 deletions

View File

@@ -44,7 +44,10 @@ def get_access_token():
log.debug(f'Status Code: {resp.status_code}')
log.debug(f'Headers: {resp.headers}')
# log.debug(f'Encoding: {resp.encoding}')
log.debug(f'JSON: {resp.json()}')
if resp.status_code == 200 and resp.json():
log.debug(f'JSON: {resp.json()}')
else:
log.warning('No JSON data found')
# log.debug('Text:', resp.text)
response_data = resp.json()
@@ -85,7 +88,10 @@ def authenticate():
log.debug(f'Status Code: {resp.status_code}')
log.debug(f'Headers: {resp.headers}')
# log.debug(f'Encoding: {resp.encoding}')
log.debug(f'JSON: {resp.json()}')
if resp.json():
log.debug(f'JSON: {resp.json()}')
else:
log.warning('No JSON data found')
# log.debug('Text:', resp.text)
if resp:

View File

@@ -74,11 +74,17 @@ class Event_Badge_Base(BaseModel):
city: Optional[str]
county: Optional[str] # NOTE: This is for a county within a state or province
country_subdivision_code: Optional[str]
state_province: Optional[str]
country: Optional[str]
location_name: Optional[str] # Actual location name shown on badge and other "public" areas
state_province_abb: Optional[str]
full_address: Optional[str]
country_alpha_2_code: Optional[str]
country: Optional[str]
# full_address: Optional[str]
location: Optional[str] # Actual location name shown on badge and other "public" areas
location_short: Optional[str] # Auto generated short version
location_long: Optional[str] # Auto generated long version
# This is updated using SQL triggers and a SQL function
# Combines informal, given, middle, family, email

View File

@@ -66,11 +66,27 @@ async def event_import_reg(
event_person_data['external_id_old'] = external_id_old
email = None
country_subdivision_code = None
state_province_abb = None
country_alpha_2_code = None
country = None
if details:
if emails := event_registrant.get('emails'):
if isinstance(emails, list) and len(emails):
email = emails[0].get('address')
if addresses := event_registrant.get('addresses'):
if isinstance(addresses, list) and len(addresses):
for address in addresses:
if primary_address := address.get('primary'):
country_subdivision_code = address.get('stateISOCode')
state_province_abb = address.get('stateAbbreviation')
if country_data := address.get('countryData'):
country_alpha_3_code = country_data.get('threeLetterIsoCode')
country_alpha_2_code = country_data.get('twoLetterIsoCode')
country = address.get('country')
event_person_profile_data = {}
event_person_profile_data['pronouns'] = event_registrant.get('gender')
event_person_profile_data['informal_name'] = event_registrant.get('preferredFirstName')
@@ -198,6 +214,32 @@ async def event_import_reg(
event_badge_data['city'] = event_registrant.get('badgeCity')
event_badge_data['state_province'] = event_registrant.get('badgeState')
if country_subdivision_code:
event_badge_data['country_subdivision_code'] = country_subdivision_code
if state_province_abb:
event_badge_data['state_province_abb'] = state_province_abb
if country_alpha_2_code:
event_badge_data['country_alpha_2_code'] = country_alpha_2_code
if country:
event_badge_data['country'] = country
location = None
if event_badge_data['city'] and state_province_abb and country_alpha_2_code and country_alpha_2_code == 'US':
city = event_badge_data['city']
location = f'{city}, {state_province_abb} {country_alpha_2_code}'
elif event_badge_data['city'] and state_province_abb and country and country == 'United States':
city = event_badge_data['city']
location = f'{city}, {state_province_abb} {country}'
elif event_badge_data['city'] and event_badge_data['state_province'] and country:
city = event_badge_data['city']
state_province = event_badge_data['state_province']
location = f'{city}, {state_province} {country}'
elif event_badge_data['city'] and country:
city = event_badge_data['city']
location = f'{city}, {country}'
if location: event_badge_data['location'] = location
event_person_data['event_badge'] = {}
event_person_data['event_badge'] = event_badge_data
@@ -205,7 +247,7 @@ async def event_import_reg(
SELECT id AS event_person_id, id_random AS event_person_id_random, external_id AS event_person_external_id, event_badge_id AS event_badge_id, event_person_profile_id AS event_person_profile_id
FROM `event_person` AS `event_person`
WHERE event_person.event_id = :event_id
AND event_person.external_id = :external_id_old
AND event_person.external_id = :external_id
/*LIMIT 1*/;
"""