init
This commit is contained in:
commit
883aa4ddb3
52
checker.py
Normal file
52
checker.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
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)
|
17
sendxmppmessage.py
Normal file
17
sendxmppmessage.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import slixmpp
|
||||||
|
|
||||||
|
|
||||||
|
class SendXmppMessage(slixmpp.ClientXMPP):
|
||||||
|
def __init__(self, jid, password, recipient, message):
|
||||||
|
slixmpp.ClientXMPP.__init__(self, jid, password)
|
||||||
|
|
||||||
|
self.recipient = recipient
|
||||||
|
self.msg = message
|
||||||
|
self.add_event_handler("session_start", self.start)
|
||||||
|
|
||||||
|
def start(self, event):
|
||||||
|
self.send_presence()
|
||||||
|
self.get_roster()
|
||||||
|
|
||||||
|
self.send_message(mto=self.recipient, mbody=self.msg, mtype='chat')
|
||||||
|
self.disconnect(wait=True)
|
Loading…
Reference in New Issue
Block a user