#NEWLINE# @ coroutine #NEWLINE# def run( self ) : #NEWLINE# #INDENT# 'Run a crawler iteration' #NEWLINE# http_client = AsyncHTTPClient ( ) #NEWLINE# try : #NEWLINE# #INDENT# response = ( yield http_client . fetch ( self . API_URL , request_timeout = REQUEST_TIMEOUT ) ) #NEWLINE# #UNINDENT# except HTTPError as ex : #NEWLINE# #INDENT# self . HTTP_ERRORS . append ( ex ) #NEWLINE# if ( len ( self . HTTP_ERRORS ) > 3 ) : #NEWLINE# #INDENT# _logger . error ( 'Too many HTTP Errors: %s' , self . HTTP_ERRORS ) #NEWLINE# #UNINDENT# return #NEWLINE# #UNINDENT# except Exception as gex : #NEWLINE# #INDENT# _logger . error ( 'Socket Error: %s' , str ( gex ) ) #NEWLINE# return #NEWLINE# #UNINDENT# if self . HTTP_ERRORS : #NEWLINE# #INDENT# del self . HTTP_ERRORS [ : ] #NEWLINE# #UNINDENT# response_json = json . loads ( response . body . decode ( 'utf-8' ) ) #NEWLINE# if ( ( not response_json ) or ( not response_json [ 'answer' ] ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# availability = response_json [ 'answer' ] [ 'availability' ] #NEWLINE# for item in availability : #NEWLINE# #INDENT# server_type = self . SERVER_TYPES . get ( item [ 'reference' ] ) #NEWLINE# if ( not server_type ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# available_zones = set ( [ e [ 'zone' ] for e in item [ 'zones' ] if ( e [ 'availability' ] not in [ 'unavailable' , 'unknown' ] ) ] ) #NEWLINE# _logger . debug ( '%s is available in %s' , server_type , available_zones ) #NEWLINE# for ( region , places ) in self . REGIONS . items ( ) : #NEWLINE# #INDENT# server_available = bool ( available_zones . intersection ( places ) ) #NEWLINE# state_id = ( '%s_available_in_%s' % ( server_type , region ) ) #NEWLINE# message = { #NEWLINE# #INDENT# 'title' : '{0} is available' . format ( server_type ) , #NEWLINE# 'text' : 'Server {server} is available in {region}' . format ( server = server_type , region = region . capitalize ( ) ) , #NEWLINE# 'url' : 'http://www.kimsufi.com/en/index.xml' , #NEWLINE# #UNINDENT# } #NEWLINE# if ( ( 'sys' in item [ 'reference' ] ) or ( 'bk' in item [ 'reference' ] ) ) : #NEWLINE# #INDENT# message [ 'url' ] = 'http://www.soyoustart.com/de/essential-server/' #NEWLINE# #UNINDENT# self . update_state ( state_id , server_available , message )