Created
May 4, 2017 05:24
-
-
Save umudkip/c3e6e9b73cb580df8765af17aa9926a5 to your computer and use it in GitHub Desktop.
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
#!/bin/python | |
#monitor USD-AUD rates | |
#uses CurrencyLayer API | |
#uses Twilio API https://www.twilio.com/docs/api/rest/message | |
import requests | |
import json | |
from twilio.rest import TwilioRestClient | |
ACCOUNT_SID = '<redact>' | |
AUTH_TOKEN = '<redact>' | |
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN) | |
'''Example resp: | |
{ | |
"success":true, | |
"terms":"https:\/\/currencylayer.com\/terms", | |
"privacy":"https:\/\/currencylayer.com\/privacy", | |
"timestamp":1487035332, | |
"source":"USD", | |
"quotes":{ | |
"USDUSD":1, | |
"USDAUD":1.304299 | |
} | |
}''' | |
def sendMessage(body): | |
message = client.messages.create(to = '+<yournumber>', from_ = '+<twilionumber>', body=body) | |
return message | |
r = requests.get('http://apilayer.net/api/live?access_key=<currencylayerapikey>¤cies=USD,AUD&format=1') | |
data = json.loads(r.text) | |
ratio = json.dumps(data['quotes']['USDAUD']) | |
print ratio | |
if float(ratio) > 1.307: #arbritrary limit to prevent spam | |
msg = "Alert! USD-AUD is: " + ratio | |
resp = sendMessage(msg) | |
print resp | |
'''msg = "USD AUD: " + ratio | |
resp = sendMessage(msg) | |
print("Sid %s. Message: %s" % (resp, msg))''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment