diff --git a/dist/netizenship-0.1.9-py3-none-any.whl b/dist/netizenship-0.1.9-py3-none-any.whl new file mode 100644 index 0000000..f7c62c2 Binary files /dev/null and b/dist/netizenship-0.1.9-py3-none-any.whl differ diff --git a/dist/netizenship-0.1.9.tar.gz b/dist/netizenship-0.1.9.tar.gz new file mode 100644 index 0000000..7be9512 Binary files /dev/null and b/dist/netizenship-0.1.9.tar.gz differ diff --git a/netizenship.py b/netizenship.py index 014c6c4..a4b0570 100644 --- a/netizenship.py +++ b/netizenship.py @@ -36,79 +36,107 @@ def banner(text, ch='=', length=78): counter = 0 # to count no of success page = requests.get(status_code_html) soup = BeautifulSoup(page.content, 'html.parser') + headers = {'user-agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Mobile Safari/537.36'} def get_website_membership(site): + + def print_fail(): + print(site.rjust(width), ':', colored(state.ljust(width//2), 'red') , '(Status:', msg, ')') + + + def print_success(): + print(site.rjust(width), ':', colored(state.ljust(width//2), 'green'), '(Status:', msg, ')') + + url = websites[site] global counter + state = "FAIL" + msg = '--exception--' + if not url[:1]=='h': link = 'https://'+uname+url else: link = url+uname - state = "FAIL" - msg = '--exception--' + try: - response = requests.get(link) + if site=='Youtube' or 'Twitter': + response = requests.get(link) + else: + response = requests.get(link, headers=headers) tag = soup.find(id=response.status_code) msg = tag.find_parent('dt').text response.raise_for_status() except: - print(site.rjust(width), ':', colored(state.ljust(width//2), 'red') , '(Status:', msg, ')') - + print_fail() + else: res_soup = BeautifulSoup(response.content, 'html.parser') if site == 'Pastebin': if len(res_soup.find_all('h1')) == 0: msg = 'broken URL' - print(site.rjust(width), ':', colored(state.ljust(width//2), 'red') , '(Status:', msg, ')') + print_fail() + else: state = 'SUCCESS' counter += 1 - print(site.rjust(width), ':', colored(state.ljust(width//2), 'green'), '(Status:', msg, ')') + print_success() + elif site == 'Wordpress': if 'doesn’t exist' or 'blocked' in res_soup: msg = 'broken URL' - print(site.rjust(width), ':', colored(state.ljust(width//2), 'red') , '(Status:', msg, ')') + print_fail() else: state = 'SUCCESS' counter += 1 - print(site.rjust(width), ':', colored(state.ljust(width//2), 'green'), '(Status:', msg, ')') + print_success() + # elif site == 'Imgur': # ToDo + elif site == 'GitLab': if 'Sign in' in res_soup.title.text: msg = 'broken URL' - print(site.rjust(width), ':', colored(state.ljust(width//2), 'red') , '(Status:', msg, ')') + print_fail() else: state = 'SUCCESS' counter += 1 - print(site.rjust(width), ':', colored(state.ljust(width//2), 'green'), '(Status:', msg, ')') + print_success() elif site == 'HackerNews': if 'No such user.' in res_soup: msg = 'No Such User!' - print(site.rjust(width), ':', colored(state.ljust(width//2), 'red') , '(Status:', msg, ')') + print_fail() else: state = 'SUCCESS' counter += 1 - print(site.rjust(width), ':', colored(state.ljust(width//2), 'green'), '(Status:', msg, ')') + print_success() + elif site == 'ProductHunt': + if 'Page Not Found' in res_soup.text: + msg = 'No Such User!' + print_fail() + else: + state = 'SUCCESS' + counter += 1 + print_success() else: state = 'SUCCESS' counter += 1 - print(site.rjust(width), ':', colored(state.ljust(width//2), 'green'), '(Status:', msg, ')') + print_success() websites = { 'Facebook': 'https://www.facebook.com/', 'Twitter': 'https://twitter.com/', 'Instagram': 'https://www.instagram.com/', 'Youtube': 'https://www.youtube.com/user/', - 'Reddit': 'https://www.reddit.com/user/', + # 'Reddit': 'https://www.reddit.com/user/', To Do + 'ProductHunt': 'https://www.producthunt.com/@', 'PInterest': 'https://www.pinterest.com/', 'Flickr': 'https://www.flickr.com/people/', 'Vimeo': 'https://vimeo.com/', 'Soundcloud': 'https://soundcloud.com/', 'Disqus': 'https://disqus.com/', - 'Medium': 'https://medium.com/', + 'Medium': 'https://medium.com/@', 'AboutMe': 'https://about.me/', # 'Imgur': 'https://imgur.com/user/', returns a landing page. to do 'Flipboard': 'https://flipboard.com/', @@ -145,16 +173,16 @@ def get_website_membership(site): # Following multithreading way goes to kind of deadlock sometime. # Help-required to debug. - with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: - try: - executor.map(get_website_membership, list(websites.keys()), timeout=5) - except: - print('Exception occured, skipping') - pass + # with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: + # try: + # executor.map(get_website_membership, list(websites.keys()), timeout=5) + # except: + # print('Exception occured, skipping') + # pass # ------for loop runs, (slowly) ------ - # for site in list(websites.keys()): - # get_website_membership(site) + for site in list(websites.keys()): + get_website_membership(site) n_websites = len(list(websites.keys())) print('Summary: User {} has membership in {}/{} websites'.format(uname, counter, n_websites)) diff --git a/pyproject.toml b/pyproject.toml index d7e9490..1d1e90f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "netizenship" -version = "0.1.8" +version = "0.1.9" description = "Tool to check the username with popular websites for membership" authors = ["Rahul Raj "] diff --git a/test_.py b/test_.py index e261bef..ef3c331 100644 --- a/test_.py +++ b/test_.py @@ -5,16 +5,19 @@ import requests from bs4 import BeautifulSoup -url = "https://news.ycombinator.com/user?id=sdsrgsdfg2222" +url = "https://www.reddit.com/user/rahulrajpl1111" +headers = {'user-agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Mobile Safari/537.36'} -response = requests.get(url) +response = requests.(url , headers=headers ) soup = BeautifulSoup(response.content, 'html.parser') -# print(soup) +print(soup.prettify()) +# print(response.status_code) # print ('----------------------') -# print((soup.find_all('div','ProfileMeta-user'))) +# print(soup.find_all('div',{'class':'_3VTI5BOpJO70xoBKSqz3O9'})) +# print(soup.find_all('h3')) -if 'No such user.' in soup: - print("Page Not Found") \ No newline at end of file +# if 'The person may have been banned' in soup.text: +# print("Page Not Found") \ No newline at end of file