def response(self): """ submits and gets response for skatteetaten request Returns ------- out : requests.models.Response response with interest rate information """ try: try: response = requests.post(url=self.url, data=self.payload(), timeout=TIMEOUT) status_code = response.status_code LOGGER.info("HTTP status code -> [{}: {}]".format( status_code, responses[status_code])) return response except ConnectTimeout as ssb_timeout_error: raise TimeOutError( "Timeout occurred - please try again later or contact system administrator, " "exited with '{}'".format(ssb_timeout_error)) except ConnectError as ssb_response_error: raise NoConnectionError( "Failed HTTP request - please insure that internet access is provided to the " "client or contact system administrator, exited with '{}'". format(ssb_response_error))
def ownership_response(self): """ Response from Finn-no housing ownership history search Returns ------- our : requests.models.Response response with housing ownership information """ try: try: start = time() owner_response = requests.get(FINN_OWNER_URL + "{}".format(self.finn_code), timeout=TIMEOUT) owner_status_code = owner_response.status_code elapsed = self.elapsed_time(start) LOGGER.info( "HTTP status code -> OWNERSHIP HISTORY: [{}: {}] -> elapsed: {}".format( owner_status_code, responses[owner_status_code], elapsed)) return owner_response except ConnectTimeout as finn_owner_timeout_error: raise TimeOutError( "Timeout occurred - please try again later or " "contact system administrator, exited with '{}'".format( finn_owner_timeout_error)) except ConnectError as finn_owner_response_error: raise NoConnectionError( "Failed HTTP request - please insure that internet access is provided to the " "client or contact system administrator, exited with '{}'".format( finn_owner_response_error))
async def stat_response(self): """ Response from Finn-no housing statistics search Returns ------- our : requests.models.Response response with housing statistics information """ try: try: start = time() async with ClientSession( timeout=ClientTimeout(TIMEOUT)) as session: async with session.get( FINN_STAT_URL + "{}".format(self.finn_code)) as stat_response: stat_status_code = stat_response.status elapsed = self.elapsed_time(start) LOGGER.info( "HTTP status code -> STATISTICS: [{}: {}] -> elapsed: {}" .format(stat_status_code, responses[stat_status_code], elapsed)) return await stat_response.content.read() except TError: raise TimeOutError( "Timeout occurred - please try again later or contact system administrator" ) except ClientConnectionError as finn_stat_response_error: raise NoConnectionError( "Failed HTTP request - please insure that internet access is provided to the " "client or contact system administrator, exited with '{}'". format(finn_stat_response_error))
def ad_response(self): """ Response from Finn-no ad housing search Returns ------- our : requests.models.Response response with housing ad information """ try: try: start = time() ad_response = requests.get(FINN_AD_URL + "{}".format(self.finn_code), timeout=TIMEOUT) ad_status_code = ad_response.status_code if ad_status_code == 404: ad_response = requests.get( FINN_AD_URL.replace('homes', 'newbuildings') + "{}".format(self.finn_code), timeout=TIMEOUT) ad_status_code = ad_response.status_code elapsed = self.elapsed_time(start) LOGGER.info( "HTTP status code -> ADVERT: [{}: {}] -> elapsed: {}".format( ad_status_code, responses[ad_status_code], elapsed)) return ad_response except ConnectTimeout as finn_ad_timeout_error: raise TimeOutError( "Timeout occurred - please try again later or contact system " "administrator, exited with '{}'".format(finn_ad_timeout_error)) except ConnectError as finn_ad_response_error: raise NoConnectionError( "Failed HTTP request - please insure that internet access is provided to the " "client or contact system administrator, exited with '{}'".format( finn_ad_response_error))
def community_stat_response(self): """ Response from Finn-no housing statistics search Returns ------- our : requests.models.Response response with housing statistics information """ try: try: start = time() community_stat_response = requests.get( FINN_COMMUNITY_URL + "{}".format(self.finn_code), timeout=TIMEOUT) stat_status_code = community_stat_response.status_code elapsed = self.elapsed_time(start) LOGGER.info( "HTTP status code -> COMMUNITY: [{}: {}] -> elapsed: {}".format( stat_status_code, responses[stat_status_code], elapsed)) return community_stat_response except ConnectTimeout as finn_community_stat_timeout_error: raise TimeOutError( "Timeout occurred - please try again later or contact system " "administrator, exited with '{}'".format(finn_community_stat_timeout_error)) except ConnectError as finn_community_stat_response_error: raise NoConnectionError( "Failed HTTP request - please insure that internet access is provided to the " "client or contact system administrator, exited with '{}'".format( finn_community_stat_response_error))
def response(self): """ Submits and gets response for SIFO request Returns ------- out : requests.Response response with expenses information """ try: start = time() parsed_sifo_url = SIFO_URL for key, item in self.family.sifo_properties().items(): parsed_sifo_url = parsed_sifo_url + key + '=' + item + '&' response = requests.post(url=parsed_sifo_url, timeout=TIMEOUT) status_code = response.status_code elapsed = self.elapsed_time(start) LOGGER.info( "HTTP status code -> SIFO: [{}: {}] -> elapsed: {}".format( status_code, responses[status_code], elapsed)) return response except URLError as sifo_response_error: if str(sifo_response_error) == "<urlopen error timed out>": raise TimeOutError( "Timeout occurred - please try again later or contact system " "administrator, exited with '{}'".format( sifo_response_error)) raise NoConnectionError( "Failed HTTP request - please insure that internet access is provided to the " "client or contact system administrator, exited with '{}'". format(sifo_response_error))
def response(self): """ Submits and gets response for posten request Returns ------- out : mechanize._response.response_seek_wrapper response with expenses information """ try: try: start = time() posten_response = requests.get(POSTEN_URL + "{}".format(self.postal_code), timeout=TIMEOUT) posten_status_code = posten_response.status_code elapsed = self.elapsed_time(start) LOGGER.info( "HTTP status code -> POSTEN: [{}: {}] -> elapsed: {}". format(posten_status_code, responses[posten_status_code], elapsed)) return posten_response except ConnectTimeout as posten_timeout_error: raise TimeOutError( "Timeout occurred - please try again later or contact system " "administrator, exited with '{}'".format( posten_timeout_error)) except ConnectError as posten_response_error: raise NoConnectionError( "Failed HTTP request - please insure that internet access is provided to the " "client or contact system administrator, exited with '{}'". format(posten_response_error))
def portalen_response(self): """ Response from finansportalen.no xml feed Returns ------- our : requests.models.Response response with mortgage information """ try: try: response = requests.post(PORTALEN_URL, auth=PORTALEN_CRED, timeout=TIMEOUT) status_code = response.status_code LOGGER.info("HTTP status code -> [{}: {}]".format( status_code, responses[status_code])) return response except ReadTimeout as portalen_timeout_error: raise TimeOutError( "Timeout occurred - please try again later or contact system administrator, " "exited with '{}'".format(portalen_timeout_error)) except ConnectError as portalen_response_error: raise NoConnectionError( "Failed HTTP request - please insure that internet access is provided to the " "client or contact system administrator, exited with '{}'". format(portalen_response_error))