Skip to content

Instantly share code, notes, and snippets.

@tonybaloney
Created December 20, 2016 05:36
Show Gist options
  • Save tonybaloney/bb849725f9bf54d21b618f06ede95be0 to your computer and use it in GitHub Desktop.
Save tonybaloney/bb849725f9bf54d21b618f06ede95be0 to your computer and use it in GitHub Desktop.
import pandas
import sys
import six
from pluralsight.licensing import LicensingAPIClient
import pluralsight.exceptions
import colorlog
import logging
handler = colorlog.StreamHandler()
handler.setFormatter(colorlog.ColoredFormatter(
'%(log_color)s%(levelname)s:%(name)s:%(message)s'))
logger = colorlog.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
# assume report file path is a command line arg
plan = sys.argv[1]
api_key = sys.argv[2]
client = LicensingAPIClient(plan, api_key)
with open('pluralsight_users_filtered.xlsx', 'rb') as f_sheet:
data = pandas.read_excel(f_sheet)
users = client.users.get_all_users()
invites = client.invites.get_all_invites()
existing_emails = [user.email for user in users]
existing_emails = existing_emails + [invite.email for invite in invites]
for index, row in data.iterrows():
if isinstance(row['Email'], six.string_types) and row['Email'].lower() in existing_emails:
logger.info("{0} {1} is already a user".format(row['First_Name'], row['Last_Name']))
else:
logger.warn("{0} {1} ({2}) is not a user".format(row['First_Name'], row['Last_Name'], row['Email']))
email = row['Email'].lower()
try:
invite = client.invites.invite_user(email, team_id=None, note=row['Business_Unit'])
print("Invited - {0}".format(invite.id))
except pluralsight.exceptions.PluralsightApiException as ex:
logger.error(ex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment