-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
45 lines (37 loc) · 1.27 KB
/
bot.py
File metadata and controls
45 lines (37 loc) · 1.27 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import time, os
from twilio.rest import Client
from twilio.http.http_client import TwilioHttpClient
from dotenv import load_dotenv
load_dotenv() # load the credentials
# Twillo has issues when it's behind a proxy, this addresses the issue.
proxy_client = TwilioHttpClient()
proxy_client.session.proxies = {'https': os.environ['https_proxy']}
# Get credentials
account_sid = os.getenv("account_sid")
auth_token = os.getenv("auth_token")
client = Client(account_sid, auth_token, http_client=proxy_client)
today = time.strftime("%m-%d")
def check_bday():
"""
A function to check if today is someone's birthday.
It reads in data from a txt file of the format 04-21 John Doe
It sends a message to the user.
"""
filename = open("file1.txt", "r")
count = 0
for line in filename:
if today in line: # There is a birthday
count = 1
message = client.messages.create(
body=f"Today is the birthday of {line[5:]}",
from_=os.getenv("twilio_num"),
to=os.getenv("my_num"))
print(message.sid)
if count == 0:
no_birthday = client.messages.create(
body="There is no birthday today!",
from_=os.getenv("twilio_num"),
to=os.getenv("my_num"))
print(no_birthday.sid)
if __name__ == "__main__":
check_bday()