Skip to content

Instantly share code, notes, and snippets.

@shaunagm
Created April 21, 2022 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunagm/76431bea97d2da46375d58cfa06edc58 to your computer and use it in GitHub Desktop.
Save shaunagm/76431bea97d2da46375d58cfa06edc58 to your computer and use it in GitHub Desktop.
Parsons authentication training script
"""
This script was created for the Parsons "All About Authentication" training.
"""
from parsons import Table, Twilio, GoogleSheets
twilio = Twilio()
sheets = GoogleSheets()
# Get data from google sheets
spreadsheet_id = "" # get from URL
people = sheets.get_worksheet(spreadsheet_id)
print(f"Got data from Google Sheet {spreadsheet_id} for:")
print(people)
# Send data to Twilio
"""note: the Parsons connector only has a few convenience functions to get data, but we can
access the underlying client"""
for person in people:
if person['Status'] == "registered":
message = f"Hi {person['Name']}, please confirm your attendance!"
elif person['Status'] == "confirmed":
message = f"Hi {person['Name']}, we're looking forward to seeing you!"
else:
continue
resp = twilio.client.messages.create(
to=f"{person['Phone #']}",
from_="+15005550006", # magic number from Twilio docs: https://www.twilio.com/docs/iam/test-credentials#test-sms-messages
body=message)
print(f"Sent text with id {resp.sid} and message {resp.body} to {person['Name']}")
"""Because we're using test credentials, we can't access our message logs. However if you were
using real credentials you could use the following:
sent_messages = twilio.get_messages()
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment