Skip to content

Commit

Permalink
Merge pull request #22 from rodekruis/feat.clean-scope
Browse files Browse the repository at this point in the history
clean scope functionality
  • Loading branch information
tijsziere authored Mar 6, 2024
2 parents afbc202 + 5c7bb59 commit f4cc6b8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import base64
import logging
import sys
import unicodedata
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
Expand Down Expand Up @@ -145,6 +146,12 @@ def clean_kobo_data(kobo_data):
kobo_data_clean[new_key] = kobo_data_clean.pop(key)
return kobo_data_clean

def clean_text(text):
# Normalize text to remove accents
normalized_text = unicodedata.normalize('NFD', text)
# Remove accents and convert to lowercase
cleaned_text = ''.join(c for c in normalized_text if not unicodedata.combining(c)).lower()
return cleaned_text

def espo_request(submission, espo_client, method, action, params=None):
"""Make a request to EspoCRM. If the request fails, update submission status in CosmosDB."""
Expand Down Expand Up @@ -309,6 +316,8 @@ async def kobo_to_121(request: Request, dependencies=Depends(required_headers_12
kobo_value = kobo_data[kobo_field].replace(" ", "_")
if target_field in intvalues:
payload[target_field] = int(kobo_data[kobo_field])
elif target_field == 'scope':
payload[target_field] = clean_text(kobo_data[kobo_field])
elif kobo_value not in attachments.keys():
payload[target_field] = kobo_data[kobo_field]
else:
Expand Down

0 comments on commit f4cc6b8

Please sign in to comment.