Almost done with Nintex bulk attendance script

This commit is contained in:
Norm Rasmussen
2025-12-05 16:56:12 -05:00
parent 008ab8708f
commit 5413e0ffd9

View File

@ -26,6 +26,8 @@ import Apikeys
import pprint
from urllib.parse import quote
from collections import defaultdict
import random
import string
pp = pprint.PrettyPrinter(indent=4)
@ -41,11 +43,10 @@ EVENT_UUID = "4787dc9f-aab2-4eb7-8790-e0e50738c52c"
FUTURE_SESH = "46102626-2966-4153-80ba-c84b5aaef31a"
PAST_SESH = "072909ff-ace8-4ef1-84bb-e93320486134"
SESH_WTH_PPL = "b3ec3a8b-ecd1-4dde-8d74-96377393026f"
PPL_LISTS = { "to_be_marked": [], "to_be_created": [], "to_be_registered": [] }
def check_if_exists(emails):
in_system = []
not_in_system = []
for email in emails:
encemail = quote(email)
try:
@ -53,19 +54,26 @@ def check_if_exists(emails):
find_person_resp = requests.get(find_person_url, headers=HEADERS).json()
person_uuid = find_person_resp["data"][0]["id"]
except Exception as e:
print(f"Error! {e} with person {email}")
# print(f"Error! {e} with person {email}")
if find_person_resp['data'] == []:
not_in_system.append(email)
PPL_LISTS['to_be_created'].extend([ email ])
else:
print(f"Person's email: {email} and uuid: {person_uuid}")
in_system.append(person_uuid)
PPL_LISTS['to_be_created'].remove(email) if email in PPL_LISTS['to_be_created'] else None
PPL_LISTS['to_be_registered'].extend([ person_uuid ])
if PPL_LISTS['to_be_created']:
ret = create_people(PPL_LISTS['to_be_created'])
#WARN: The status code will be 202 even with an empty list for emails!!
if str(ret).startswith('20'):
PPL_LISTS['to_be_created'] = []
else:
print("To Be Created List is now Empty")
return "Something"
return not_in_system, in_system
def create_people(emails):
load_list = []
print(str(emails)[2:-2])
if len(emails) > 1:
for people in emails:
miniload = {"email": people, "groups": ""}
@ -76,13 +84,13 @@ def create_people(emails):
bulk_create = f"{BASEURL}/bulk/people"
bulk_invite = requests.post(url=bulk_create, headers=HEADERS, json=payload)
print(payload)
check_if_exists(emails)
return bulk_invite.status_code
def check_attendance():
df = pd.read_csv(IMPORTFILE)
emails = df["Email"].unique()
def check_attendance(emails):
# df = pd.read_csv(IMPORTFILE)
# emails = df["Email"].unique()
attendees = []
check_attendance_url = f"{BASEURL}training_events/{EVENT_UUID}/training_sessions/{SESH_WTH_PPL}/registrants"
check_attendance_resp = requests.get(check_attendance_url, headers=HEADERS).json()
@ -92,29 +100,23 @@ def check_attendance():
person_email = person['attributes']['person_email']
attendees.append((person_uuid, person_email, attendance_uuid))
# registered_emails, non_registered = compare_csv_to_registrants(emails, attendees)
return compare_csv_to_registrants(emails, attendees)
def register_for_session(in_system):
def register_for_session(to_register):
pass
def compare_csv_to_registrants(emails, attendees):
tuple_mapping = defaultdict(list)
# NOTE: Some logic. Emails given to script. Session registrants grabbed. If email is on registered list, mark as attended. If email is NOT on registered list, check if they exist. If they exist, register+mark as attended. If they don't, create user, then register+mark as attended.
for person in attendees:
tuple_mapping[person[1]].append(person)
registered_emails = []
not_registered_emails = []
for item in emails:
if item in tuple_mapping:
registered_emails.extend(tuple_mapping[item])
else:
not_registered_emails.append(item)
return registered_emails, not_registered_emails
def mark_attendance(tuple_list):
@ -127,17 +129,37 @@ def mark_attendance(tuple_list):
mark_attended = requests.post(attendance_url, headers=HEADERS, json=payload)
return mark_attended.status_code
def generate_random_email():
"""
Generates a random email address using built-in Python modules.
"""
domains = ["gmail.com", "yahoo.com", "outlook.com", "example.com", "test.com"]
username_characters = string.ascii_lowercase + string.digits
username_length = random.randint(6, 12)
username = ''.join(random.choice(username_characters) for i in range(username_length))
domain = random.choice(domains)
email = f"{username}@{domain}"
return email
if __name__ == "__main__":
lists = check_attendance()
not_in_system, in_system = check_if_exists(lists[1])
if not_in_system is not None:
create_people(not_in_system)
emails = []
for _ in range(5):
email = generate_random_email()
emails.append(email)
emails.append('norm35@norm.com')
lists = check_attendance(emails) # returns registered_emails, not_registered_emails
PPL_LISTS['to_be_marked'] = lists[0]
check_if_exists(lists[1])
while not PPL_LISTS['to_be_created']:
register_for_session()
# TODO: Something needs to be added here. After we add the people, we need to check them again for check if exists and then that should go straight into the register function. That should make the data flow more reusable.
# This could be a for loop until all the non-emails have been added, they are then grouped back with all the other non-registered users, and then flow through the registration functions.
"""
So the flow would be:
get CSV and grab all emails
compare emails to registrations
X get CSV and grab all emails
X compare emails to registrations
emails that are registered go over to the mark as attended bucket.
emails that are not registered, are checked if they exist
if they exist, they are on hold.