diff --git a/Basic-Scripts/Password/README.md b/Basic-Scripts/Password/README.md new file mode 100644 index 00000000..cab9cd12 --- /dev/null +++ b/Basic-Scripts/Password/README.md @@ -0,0 +1,4 @@ +

Hard to guess easy to remember

+

Python script to generate a password which is almost impossible to guess by a attacker, by using the easily remembered words of a user day to day life.

+ +Here I use built-in python module name random use to make random choice. diff --git a/Basic-Scripts/Password/password.py b/Basic-Scripts/Password/password.py new file mode 100644 index 00000000..cb3f3580 --- /dev/null +++ b/Basic-Scripts/Password/password.py @@ -0,0 +1,71 @@ +#Importing Library +import random + +#GENERATE TWO RANDOM STRINGS FROM THE GIVEN LIST +def RandomString(List): + string1=random.choice(List) #First random string + List.remove(string1) #To avoid repetition of strings removing the first word from the list + string2=random.choice(List) #second random string + + return string1,string2 + +#GENERATE TWO RANDOM NUMBERS BETWEEN RANGE (0 - 9) +def RandomNumber(): + List=[0,1,2,3,4,5,6,7,8,9] + number1=random.choice(List) #First random number + List.remove(number1) #To avoid repetition of numbers removing the first word from the list + number2=random.choice(List) #Second random number + + return number1,number2 + +#GENERATE TWO RANDOM CHARACTERS +def RandomSpecialChar(): + List=['~','`','!','@','#','$','%','^','&','*','?','+','-','_',';',':','>','<'] + char1=random.choice(List) #First random character + List.remove(char1) #To avoid repetition of characters removing the first word from the list + char2=random.choice(List) #Second random character + + return char1,char2 + +#GENERATE A RANDOM INDEX FROM PASSWORD STRING +def RandomIndex(List): + index=random.choice(List) + List.remove(index) + + return index + +#Driver program +if __name__=='__main__': + + #Take input from user + names=list(input('Input the list of easily remembered words').split()) + + #Creating password using two strings + string=RandomString(names) + password=string[0]+string[1] + + #Uppercasing random characters in password + IndexList=list(range(0,len(password))) + index=RandomIndex(IndexList) + password=password[:index]+password[index].upper()+password[index+1:] + index=RandomIndex(IndexList) + password=password[:index]+password[index].upper()+password[index+1:] + + #Adding random numbers in password + number=RandomNumber() + index=RandomIndex(IndexList) + password=password[:index]+str(number[0])+password[index:] + index=RandomIndex(IndexList) + password=password[:index]+str(number[1])+password[index:] + + #Adding random special symbols in password + char=RandomSpecialChar() + index=RandomIndex(IndexList) + password=password[:index]+char[0]+password[index:] + index=RandomIndex(IndexList) + password=password[:index]+char[1]+password[index:] + + #Printing the generated password + print('Generated password : ',password) + + diff --git a/Web-Scraping/Covid-19 Statics/README.md b/Web-Scraping/Covid-19 Statics/README.md new file mode 100644 index 00000000..553d0ab7 --- /dev/null +++ b/Web-Scraping/Covid-19 Statics/README.md @@ -0,0 +1,6 @@ +

Scraping Covid-19 Statics

+ +Scraping the corona virus cases of 213 countries and territories. +Using Beautiful soup python package to extract the HTML content of the website(https://www.worldometers.info/coronavirus/countries-where-coronavirus-has-spread/). + +Representing the extracted data in table format form using texttable python library. diff --git a/Web-Scraping/Covid-19 Statics/code.py b/Web-Scraping/Covid-19 Statics/code.py new file mode 100644 index 00000000..08680fb1 --- /dev/null +++ b/Web-Scraping/Covid-19 Statics/code.py @@ -0,0 +1,52 @@ +# Importing Libraries +import requests +from bs4 import BeautifulSoup +import texttable as tt + +# URL for scrapping data +url = 'https://www.worldometers.info/coronavirus/countries-where-coronavirus-has-spread/' + +# Get URL html +page = requests.get(url) +soup = BeautifulSoup(page.text, 'html.parser') + +data = [] + +# soup.find_all('td') will scrape every element in the url's table +data_iterator = iter(soup.find_all('td')) +# data_iterator is the iterator of the table + +# This loop will keep repeating till there is data available in the iterator +while True: + try: + country = next(data_iterator).text + confirmed = next(data_iterator).text + deaths = next(data_iterator).text + continent = next(data_iterator).text + deaths=deaths.replace(',','') #Removing "," from deaths string + confirmed=confirmed.replace(',','') #Removing "," from confirmed string + + # For 'confirmed' and 'deaths', make sure to remove the commas and convert to int + data.append(( + country, + int(confirmed), #Converting string to int + int(deaths), #Converting string to int + continent + )) + + # StopIteration error is raised when there are no more elements left to iterate through + except StopIteration: + break + +# Sort the data by the number of confirmed cases +data.sort(key = lambda row: row[1], reverse = True) + +# Creating Table +table = tt.Texttable() +table.add_rows([(None, None, None, None)] + data) # Add an empty row at the beginning for the headers +table.set_cols_align(('c', 'c', 'c', 'c')) # 'l' denotes left, 'c' denotes center, and 'r' denotes right +table.header((' Country ', ' Number of cases ', ' Deaths ', ' Continent ')) + +# Printing the created table +print(table.draw()) +