I've been running a feed for about a year. Most of the time, I'm under 20 listeners at a time. I had some event the other day where my listeners peaked at nearly 200. I wish I would have been notified at the time of the event so I could have added a feed alert or something...and potentially driven up the number of listeners further.
So I whipped up a python script to do just that. Here it is if anyone else wants to implement the same feature. This runs on a Raspberry Pi that supplies my feed.
This file is located at /home/pi/stats/stats.py
I then have then running every 5 minutes thanks to a cronjob:
then add the line
The "mail" command above requires ssmtp & mailutils to be installed (ssmtp to send emails – Raspberry Pi Projects) which I have configured to send via a gmail account.
So I whipped up a python script to do just that. Here it is if anyone else wants to implement the same feature. This runs on a Raspberry Pi that supplies my feed.
This file is located at /home/pi/stats/stats.py
Code:
#!/usr/bin/python
import urllib2, json
import os
feedId = "put_your_radioreference_feedId_here"
username = "put_your_radioreference_username_here"
password = "put_your_radioreference_password_here"
email = "put_your_email_here"
alertThreshold = 30
alertSubject = "[elmpi] Broadcastify Alert"
alertBody = "Broadcastify listener threshold exceeded " + str(alertThreshold) + " listeners. "
alertBody += "Listen to the feed here http://www.broadcastify.com/listen/feed/" + feedId + " "
alertBody += "Manage the feed here http://www.broadcastify.com/manage/feed/" + feedId + " "
url = "https://api.broadcastify.com/owner/?a=feed&feedId=" + feedId + "&type=json&u=" + username + "&p=" + password
response = urllib2.urlopen(url)
data = json.load(response)
listeners = data['Feed'][0]['listeners']
alertBody += "The current number of listeners is " + str(listeners) + " "
if listeners > alertThreshold:
cmd = 'echo ' + alertBody + ' | mail -s "' + alertSubject + '" ' + email
os.system(cmd)
I then have then running every 5 minutes thanks to a cronjob:
Code:
crontab -e
then add the line
Code:
*/5 * * * * /home/pi/stats/stats.py
The "mail" command above requires ssmtp & mailutils to be installed (ssmtp to send emails – Raspberry Pi Projects) which I have configured to send via a gmail account.