Skip to content

Instantly share code, notes, and snippets.

@erikgregorywebb
Created November 6, 2019 21:54
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 erikgregorywebb/b5675a8bd3be2d1969ba1b246f94f333 to your computer and use it in GitHub Desktop.
Save erikgregorywebb/b5675a8bd3be2d1969ba1b246f94f333 to your computer and use it in GitHub Desktop.
import datetime
import requests
import pandas as pd
import re
from twilio.rest import Client
import time
# get birthday list
headers = {'Authorization': 'Bearer YOUR-BEARER-TOKEN-HERE'}
uri = 'https://coda.io/apis/v1beta1/docs/Blf1pjHgNu/tables/eq_birthdays/rows'
res = requests.get(uri, headers=headers).json()
# unpack
items = res['items']
rows = []
for item in items:
name = item['values']['c-IqS2KcMdol']
birthday = item['values']['c-8q8TXIknjd']
phone = item['values']['c-7SJl4vYxT3']
row = [name, birthday, phone]
rows.append(row)
df = pd.DataFrame(rows)
df.columns = ['name', 'birthday', 'phone']
df = df.sort_values('name')
# clean birthdays
df['birthday'] = pd.to_datetime(df['birthday'])
df['birthday'] = df['birthday'].dt.strftime("%m-%d")
# clean phone numbers
def remove_chars(s):
return re.sub('[^0-9]+', '', s)
df['phone'] = '+1' + df['phone'].apply(remove_chars)
# determine current date
today = datetime.datetime.now()
today = today.strftime("%m-%d")
# filter
birthdays = df[df.birthday == today]
print(birthdays)
# create client
account_sid = 'YOUR-ACCOUNT-SID-HERE'
auth_token = 'YOUR-AUTH-TOKEN-HERE'
client = Client(account_sid, auth_token)
# define function
def sendMessage(recipient_number):
message = client.messages.create(
body = "Happy Birthday! Have a wonderful day",
from_ = '+YOUR-TWILIO-NUMBER_HERE',
to = recipient_number
)
# send messages
for i in range(0, len(birthdays)):
recipient_number = birthdays.iloc[i, 2]
sendMessage(recipient_number)
print(recipient_number)
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment