import requests

from templates.text import TextTemplate

def process(input, entities):
    output = {}
    try:
        url = entities['url'][0]['value']
        strip_list = ['http://', 'https://', '/']
        for item in strip_list:
            url = url.strip(item)
        r = requests.get('https://isitup.org/' + url + '.json')
        data = r.json()
        status = data['status_code']
        if status == 1:
            text = url + ' is up.'
        elif status == 2:
            text = url + ' seems to be down!'
        elif status == 3:
            text = 'Please enter a valid domain to check availability.'
        else:
            raise Exception("Something unexpected happened!")
        output['input'] = input
        output['output'] = TextTemplate(text).get_message()
        output['success'] = True
    except:
        error_message = 'There seems to be a problem looking up that domain.'
        error_message += '\nPlease ask me something else, like:'
        error_message += '\n - is google.com up'
        error_message += '\n - google.com status'
        error_message += '\n - ping google.com'
        output['error_msg'] = TextTemplate(error_message).get_message()
        output['success'] = False
    return output

@@ -49,16 +49,46 @@
 Template
+%0Afrom urlparse import urlparse
 %0A%0Adef pr
@@ -190,114 +190,225 @@
     
-strip_list = %5B'
+if not urlparse(url).scheme:%0A            url = %22
 http
+s
 ://
-', 'https://', '/'%5D%0A        for item in strip_list:%0A            url = url.strip(item
+%22 + url%0A        hostname = urlparse(url).hostname%0A        if hostname is None:%0A            raise Exception(%22Please enter a valid hostname to check availability.%22
 )%0A  
@@ -454,19 +454,24 @@
 org/' + 
-url
+hostname
  + '.jso
@@ -574,27 +574,32 @@
      text = 
-url
+hostname
  + ' is up.'
@@ -644,19 +644,24 @@
  text = 
-url
+hostname
  + ' see

Handle URLs with path / parameters (#204)