53 lines
1.9 KiB
Python
53 lines
1.9 KiB
Python
from sendxmppmessage import SendXmppMessage
|
|
|
|
import requests
|
|
from time import sleep
|
|
from random import randint
|
|
|
|
|
|
URL = 'https://www.ovh.com/engine/api/dedicated/server/availabilities?country=fi'
|
|
SERVICE_URL = 'https://www.kimsufi.com/fi/tilaus/kimsufi.xml?reference='
|
|
SERVICES = ['service1', 'service2'] # for example ['1801sk12', '1801sk13']
|
|
REGION = 'europe' # europe, northAmerica, apac
|
|
DATACENTERS = ['gra', 'rbx'] # https://www.ovh.com/world/about-us/datacenters.xml
|
|
HEADERS = {
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) '
|
|
'AppleWebKit/537.36 (KHTML, like Gecko) '
|
|
'Chrome/65.0.3315.4 Safari/537.36'
|
|
}
|
|
|
|
JID = 'user@example.com'
|
|
PW = 'password'
|
|
TO = 'user2@example.com'
|
|
|
|
|
|
def send_message(message):
|
|
con = SendXmppMessage(JID, PW, TO, message)
|
|
con.register_plugin('xep_0030') # Service Discovery
|
|
con.register_plugin('xep_0199') # XMPP Ping
|
|
con.connect()
|
|
con.process(forever=False)
|
|
|
|
|
|
while True:
|
|
try:
|
|
print('Trying to get the data')
|
|
response = requests.get(URL, headers=HEADERS).json()
|
|
print('Checking for availability')
|
|
for row in response:
|
|
for service in SERVICES:
|
|
if row['hardware'] == service:
|
|
if row['region'] == REGION:
|
|
for location in row['datacenters']:
|
|
if location['availability'] != 'unavailable' and location['datacenter'] in DATACENTERS:
|
|
whole_url = SERVICE_URL + service
|
|
print(whole_url + ' in ' + location['datacenter'] + ' is available')
|
|
message = whole_url + ' ' + 'is available in ' + location['datacenter']
|
|
send_message(message)
|
|
except Exception as e:
|
|
print(e)
|
|
continue
|
|
wait_for_sec = randint(60, 180)
|
|
print('Waiting for ' + str(wait_for_sec) + 's before new check')
|
|
sleep(wait_for_sec)
|