Skip to content

Instantly share code, notes, and snippets.

@kumekay
Created June 8, 2015 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumekay/15b70cb0b7990b66af81 to your computer and use it in GitHub Desktop.
Save kumekay/15b70cb0b7990b66af81 to your computer and use it in GitHub Desktop.
Kimsufi server Availability checker and notifier (via PushBullet)
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