-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitch_SMS_notifs.py
42 lines (34 loc) · 1.19 KB
/
twitch_SMS_notifs.py
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
"""
Twitch Live SMS Notifier
Author: Ilias Kamal
Email: [email protected]
Date: March 24, 2023
Description: This script checks if a specific Twitch channel is live and sends an SMS notification using Twilio if it is.
"""
import requests
from twilio.rest import Client
# Set up Twilio client with your Account SID and Auth Token
client = Client("YOUR_ACCOUNT_SID", "YOUR_AUTH_TOKEN")
# Set up Twitch API endpoint and headers
endpoint = "https://api.twitch.tv/helix/streams"
headers = {"Client-ID": "YOUR_TWITCH_CLIENT_ID"}
# Set the Twitch channel name to check
channel_name = "YOUR_TWITCH_CHANNEL_NAME"
# Set the phone number to receive SMS alerts
phone_number = "YOUR_PHONE_NUMBER"
# Check if the Twitch channel is live
response = requests.get(endpoint, headers=headers, params={"user_login": channel_name})
data = response.json()
is_live = False
if "data" in data and len(data["data"]) > 0:
is_live = True
# Send an SMS alert if the channel is live
if is_live:
message = client.messages.create(
to=phone_number,
from_="YOUR_TWILIO_PHONE_NUMBER",
body=f"{channel_name} is now live on Twitch!"
)
print("SMS message sent!")
else:
print("Channel is not live.")