Last active
July 25, 2020 16:00
-
-
Save h3mantD/10237edf6544b2b8fc6668d95cac223e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import string | |
def find_string(string,sub_string): | |
return string.find(sub_string) | |
url = input() | |
try: | |
data = urllib.request.urlopen(url) | |
except urllib.error.URLError as e: ResponseData = e.read().decode("utf8", 'ignore') | |
except urllib.error.HTTPError as e: ResponseData = e.read().decode("utf8", 'ignore') | |
st_code = data.getcode() | |
directory1= {} | |
try: | |
if st_code == 200: | |
sub_string = ".txt" | |
res = find_string(url,sub_string) | |
if res > 0: | |
r = data.read().decode('UTF-8') | |
data3 = str(r) | |
list1 = data3.split('\n') | |
count = 0 | |
for line in list1: | |
one = line.lower() | |
Str2=' ' | |
for l in one: | |
if l.isalnum(): | |
Str2=Str2+l | |
count+=1 | |
newstr = Str2[1:] | |
revstr=newstr[::-1] | |
#print("normal :"+newstr) | |
#print("reverse :"+revstr) | |
if revstr == newstr: | |
#print(newstr) | |
directory1[count]=len(newstr) | |
directory1.popitem() | |
print(directory1) | |
print("File ok") | |
else: | |
print("file is not a text file") | |
else: | |
print("the URL is incorrect") | |
except urllib.error.URLError as e: | |
print("error" +e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment