Created
June 8, 2015 10:36
-
-
Save kumekay/15b70cb0b7990b66af81 to your computer and use it in GitHub Desktop.
Kimsufi server Availability checker and notifier (via PushBullet)
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
import json | |
import codecs | |
import requests | |
import random | |
def get_states(reference = ["150sk30", "150sk40"]): | |
states = {} | |
anyAvailable = False | |
body = requests.get('https://ws.ovh.com/dedicated/r2/ws.dispatcher/getAvailability2').json() | |
for r in reference: | |
for i in body["answer"]["availability"]: | |
if i["reference"] == r: | |
for m in i["metaZones"]: | |
if m['availability'] != "unknown": | |
states[r] = True | |
anyAvailable = True | |
return states, anyAvailable | |
def push_me(data, title = "Servers Available"): | |
token = "Bearer XXXXXXXXXXXXX" # Push bullet API key | |
url = 'https://api.pushbullet.com/v2/pushes' | |
headers = {'Authorization': token} | |
payload = {'type': 'link', 'title': title, 'body': data, 'url': "http://www.kimsufi.com/en/"} | |
r = requests.post(url, headers=headers, data=payload) | |
return r.json() | |
if __name__ == "__main__": | |
states, anyAvailable = get_states() | |
if anyAvailable: | |
push_me(states) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment