傳送單一 SMS 簡訊
依照規定,Elena 在工作以外請 Sam 幫她替最大額的捐款人傳送感謝的 SMS 簡訊。
Sam 認同 Elena 的目標,所以決定幫忙。
她打算寫一個小腳本,跑過 Elena 的聯絡人清單,並送出感謝訊息。
因為這只是一次性的執行,Sam 也不會定期通知這些人,所以不需要建立 topic 並讓他們訂閱。
Sam 已經建立好 boto3 的 SNS 用戶端並存放在變數 sns。變數 contacts 以 DataFrame 形式包含了 Elena 的聯絡人。
請幫 Sam 為 Elena 最大的支持者們組合一段簡短的問候與致謝!
本練習屬於課程
Python 中的 AWS Boto 入門
練習說明
- 對每位聯絡人,臨時傳送一則 SMS 到該聯絡人的電話號碼。
- 訊息內容應包含聯絡人的姓名。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Loop through every row in contacts
for idx, row in contacts.iterrows():
# Publish an ad-hoc sms to the user's phone number
response = sns.____(
# Set the phone number
____ = str(row['Phone']),
# The message should include the user's name
____ = 'Hello {}'.____(row['Name'])
)
print(response)