Last active
September 5, 2015 21:13
-
-
Save RobSpectre/fc3966640699f4a96d3f to your computer and use it in GitHub Desktop.
Example Twitter alert checker using Twilio
This file contains 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
from twilio.rest import TwilioRestClient | |
import simplejson as json | |
from time import sleep | |
class SocialAlarm(object): | |
def __init__(self): | |
self.counter = 1 | |
def check_json(self): | |
file_handler = open("output.json", 'r') | |
data = json.load(file_handler) | |
file_handler.close() | |
for item in data: | |
if item['counter'] >= 5: | |
client = TwilioRestClient() | |
client.messages.create(from_="(929) xxx-xxxx", | |
to=item['phone_number'], | |
body="YO. GET OFF TWITTER.") | |
return str("Sending text message...") | |
def main(self): | |
print("Checking the JSON file for counters for the {} " | |
"time...".format(self.counter)) | |
self.check_json() | |
print("Sleeping for 10 seconds...") | |
sleep(10) | |
self.counter += 1 | |
return self.main() | |
if __name__ == "__main__": | |
social_alarm = SocialAlarm() | |
social_alarm.main() |
This file contains 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
[{"phone_number": "+1718xxxxxxx", "counter": 5}, {"phone_number": "+1415xxxxxxx", "counter": 1}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment