Skip to content

Instantly share code, notes, and snippets.

@maebert
Last active August 29, 2018 04:30
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maebert/0166aa566cd04151be03 to your computer and use it in GitHub Desktop.
Save maebert/0166aa566cd04151be03 to your computer and use it in GitHub Desktop.
Get notified when somebody posts a new topic in a forum
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)
@muloka
Copy link

muloka commented Sep 16, 2014

Congrats on the ticket search to attend this year's 🔥

Have you been before?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment