Last active
August 29, 2018 04:30
-
-
Save maebert/0166aa566cd04151be03 to your computer and use it in GitHub Desktop.
Get notified when somebody posts a new topic in a forum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71750 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
KIMONO_API_KEY = "<MY_API_KEY>" | |
TWILIO_ACCOUNT_NUMBER = "<TWILIO_ACCOUNT_NUMBER>" | |
TWILIO_API_KEY = "<TWILIO_API_KEY>" | |
TWILIO_API_SECRET = "<TWILIO_API_SECRET>" | |
MY_TWILIO_NUMBER = "+1234567890" | |
NOTIF_RECIPIENTS = ('+1 415 123-4567', '+44 20 1234567' '+81 3 12345678') | |
URL = "https://www.kimonolabs.com/api/6zzoaezg?apikey={KIMONO_API_KEY}".format(**locals()) | |
response = requests.get(URL).json() | |
data = response['results']['collection1'] | |
latest_topic = int(open('latest_topic.txt').read()) | |
max_topic = latest_topic | |
new_posts = [] | |
for post in data: | |
topic = int(post['Title']['href'].split('t=')[-1]) | |
if topic > latest_topic: | |
new_posts.append(post) | |
max_topic = max(max_topic, topic) | |
with open('latest_topic.txt', 'w') as f: | |
f.write(str(max_topic)) | |
def send_message(post, number): | |
URL = "https://api.twilio.com/2010-04-01/Accounts/{TWILIO_ACCOUNT_NUMBER}/SMS/Messages.json".format(**locals()) | |
text = "{}: '{}' ({} replies) {}".format( | |
post['Date']['text'], | |
post['Title']['text'], | |
post['Replies'], | |
post['Title']['href'] | |
) | |
params = { | |
"From": MY_TWILIO_NUMBER, | |
"To": number, | |
"Body": text | |
} | |
requests.post(URL, data=params, auth=(TWILIO_API_KEY, TWILIO_API_SECRET)) | |
for post in new_posts: | |
for number in NOTIF_RECIPIENTS: | |
send_message(post, number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Congrats on the ticket search to attend this year's 🔥
Have you been before?