这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@Wert1996
Copy link
Contributor

@Wert1996 Wert1996 commented Jun 9, 2017

Checks whether a web domain is up or not using isitup.org. Needs to learn 'Is xyz.com up', 'xyz.com status'.

Copy link
Owner

@swapagarwal swapagarwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The structure looks good overall. 😄

'url',
'video',
'weather',
'webcheck',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename it to ping module? It's more intuitive.

strip_list = ['http://','https://','/']
for item in strip_list:
url = url.strip(item)
page = requests.get('https://isitup.org/'+str(url))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pro Tip: See what happens if you append .json to the end of the URL..

@Wert1996
Copy link
Contributor Author

Thanks for the feedback! Applied the proposed changes :)

Copy link
Owner

@swapagarwal swapagarwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The training for this module is complete. Address the following comments, and this module is good to go! 😄

@@ -0,0 +1,35 @@
import requests
import json
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed.

for item in strip_list:
url = url.strip(item)
page = requests.get('https://isitup.org/'+url+'.json')
page = json.loads(page.text)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you see the other modules, the general structure is:
r = requests.get(...)
data = r.json()

output['error_msg'] = TextTemplate(error_message).get_message()
output['success'] = False
return output

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra line.

output['success'] = True
except:
error_message = 'There seems to be some problem'
error_message = '\nPlease ask me something else, like:'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be "+=". Check the below lines too.

page = json.loads(page.text)
status = page['status_code']
if status == 1:
txt = orig_url + ' is up!'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use original url here, as that might be misleading. Use the one that we passed in the api call.

txt = orig_url + ' is up!'
elif status == 2:
txt = orig_url + ' seems to be down!'
else :
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know the status code here? If yes, then we should use that here instead. Any unexpected status codes should result in an error.

strip_list = ['http://','https://','/']
for item in strip_list:
url = url.strip(item)
page = requests.get('https://isitup.org/'+url+'.json')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing around +

try:
url = entities['url'][0]['value']
orig_url = url
strip_list = ['http://','https://','/']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space after comma. Can you explain why the third entry in the list is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coz queries like google.com/ will cause wrong domain name error.

@swapagarwal swapagarwal merged commit 04508c5 into swapagarwal:master Jun 16, 2017
@Wert1996
Copy link
Contributor Author

Thanks @swapagarwal :)

@Wert1996 Wert1996 deleted the isitup branch June 16, 2017 19:05
@swapagarwal
Copy link
Owner

Congratulations! 🎉
Good work on your first pull request. 😄

@swapagarwal swapagarwal mentioned this pull request Jun 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants