From dd36f6ca8b7ecb5d532cdfc6794d63148d9eabf8 Mon Sep 17 00:00:00 2001 From: Suraj Jadhav Date: Thu, 19 Nov 2020 12:51:24 +0530 Subject: [PATCH 1/2] added support for urls without http/s --- readit/cli.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/readit/cli.py b/readit/cli.py index a8d4dcc..0cb2ab9 100644 --- a/readit/cli.py +++ b/readit/cli.py @@ -61,8 +61,16 @@ def main( for url_to_add in add: url = url_to_add try: - validate_url = requests.get(url) - validate_code = validate_url.status_code + if (url.startswith(("http://", "https://"))): + validate_code = requests.get(url).status_code + elif requests.get("http://" + url).status_code == 200: + validate_code = 200 + url = "http://" + url + elif requests.get("https://" + url).status_code == 200: + validate_code = 200 + url = "https://" + url + else: + validate_code = 0 if validate_code == 200: is_url_added = database_connection.add_url(url) if is_url_added: @@ -98,8 +106,16 @@ def main( url_id = url_list[0] url = url_list[1] try: - validate_url = requests.get(url) - validate_code = validate_url.status_code + if (url.startswith(("http://", "https://"))): + validate_code = requests.get(url).status_code + elif requests.get("http://"+url).status_code == 200: + validate_code = 200 + url = "http://" + url + elif requests.get("https://"+url).status_code == 200: + validate_code = 200 + url = "https://" + url + else: + validate_code = 0 if validate_code == 200: is_url_updated = database_connection.update_url(url_id, url) if is_url_updated: @@ -183,8 +199,16 @@ def main( for url_to_add in insert: url = url_to_add try: - validate_url = requests.get(url) - validate_code = validate_url.status_code + if (url.startswith(("http://", "https://"))): + validate_code = requests.get(url).status_code + elif requests.get("http://"+url).status_code == 200: + validate_code = 200 + url = "http://" + url + elif requests.get("https://"+url).status_code == 200: + validate_code = 200 + url = "https://" + url + else: + validate_code = 0 if validate_code == 200: is_url_added = database_connection.add_url(url) if is_url_added: @@ -209,7 +233,6 @@ def main( else: print("URL is already bookmarked. Check URL information. See help") - def option_yes_no(): """ Asks whether to bookmark invalid URLs or Offline URLs to database. From 37e5590866aa14533a99d892bac24f83f1ec2acf Mon Sep 17 00:00:00 2001 From: Suraj Jadhav Date: Thu, 19 Nov 2020 13:12:13 +0530 Subject: [PATCH 2/2] added 1 blank line --- readit/cli.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/readit/cli.py b/readit/cli.py index 0cb2ab9..99515a4 100644 --- a/readit/cli.py +++ b/readit/cli.py @@ -61,7 +61,7 @@ def main( for url_to_add in add: url = url_to_add try: - if (url.startswith(("http://", "https://"))): + if url.startswith(("http://", "https://")): validate_code = requests.get(url).status_code elif requests.get("http://" + url).status_code == 200: validate_code = 200 @@ -106,12 +106,12 @@ def main( url_id = url_list[0] url = url_list[1] try: - if (url.startswith(("http://", "https://"))): + if url.startswith(("http://", "https://")): validate_code = requests.get(url).status_code - elif requests.get("http://"+url).status_code == 200: + elif requests.get("http://" + url).status_code == 200: validate_code = 200 url = "http://" + url - elif requests.get("https://"+url).status_code == 200: + elif requests.get("https://" + url).status_code == 200: validate_code = 200 url = "https://" + url else: @@ -199,12 +199,12 @@ def main( for url_to_add in insert: url = url_to_add try: - if (url.startswith(("http://", "https://"))): + if url.startswith(("http://", "https://")): validate_code = requests.get(url).status_code - elif requests.get("http://"+url).status_code == 200: + elif requests.get("http://" + url).status_code == 200: validate_code = 200 url = "http://" + url - elif requests.get("https://"+url).status_code == 200: + elif requests.get("https://" + url).status_code == 200: validate_code = 200 url = "https://" + url else: @@ -233,6 +233,7 @@ def main( else: print("URL is already bookmarked. Check URL information. See help") + def option_yes_no(): """ Asks whether to bookmark invalid URLs or Offline URLs to database.