-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
26 lines (20 loc) · 806 Bytes
/
utils.py
File metadata and controls
26 lines (20 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import boto3
import random
import string
sns_client = boto3.client('sns') # TODO: how to auth on server
# TODO: use https://pypi.org/project/phonenumbers/ to validate number
def send_sms(phone_number: str, message: str, **kwargs):
"""Send an SMS to the provided phone number"""
if not phone_number.startswith('+'):
phone_number = '+1' + phone_number
return sns_client.publish(
PhoneNumber=phone_number,
Message=message,
**kwargs
)
def random_code(stringLength: int=6):
"""Generate a random string of letters and digits.
Totally copy-pasta'ed https://pynative.com/python-generate-random-string/
"""
lettersAndDigits = string.ascii_letters + string.digits
return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))