Skip to content

Instantly share code, notes, and snippets.

View ChaitanyaBaweja's full-sized avatar

Chaitanya Baweja ChaitanyaBaweja

View GitHub Profile
## Importing Necessary Modules
import requests # to get image from the web
import shutil # to save it locally
## Set up the image URL and filename
image_url = "https://cdn.pixabay.com/photo/2020/02/06/09/39/summer-4823612_960_720.jpg"
filename = image_url.split("/")[-1]
# Open the url image, set stream to True, this will return the stream content.
r = requests.get(image_url, stream = True)
from difflib import get_close_matches
population_dict = {'china':1439, 'india':1380, 'usa':331, 'france':65,'germany':83, 'spain':46}
while(True):
Country_Name = input('Please enter Country Name(type exit to close): ').lower()
# break from code if user enters exit
if Country_Name == 'exit':
break
from difflib import get_close_matches
print(get_close_matches("chinna", ['china','france','india','usa']))
# Output
# ['china']
from difflib import SequenceMatcher # import
# creating a SequenceMatcher object comparing two strings
check = SequenceMatcher(None, 'chinna', 'china')
# printing a similarity ratio on a scale of 0(lowest) to 1(highest)
print(check.ratio())
# Output
# 0.9090909090909091
population_dict = {'china':1439, 'india':1380, 'usa':331, 'france':65,'germany':83, 'spain':46}
while(True):
Country_Name = input('Please enter Country Name(type exit to close): ').lower()
# break from code if user enters exit
if Country_Name == 'exit':
break
# keys (Country Names) are now all lowercase
population_dict = {'china':1439, 'india':1380, 'usa':331, 'france':65,'germany':83, 'spain':46}
Country_Name = input('Please enter Country Name: ').lower() # lowercase input
print(population_dict[Country_Name])
# population in millions. (Source: https://www.worldometers.info/world-population/population-by-country/)
population_dict = {'China':1439, 'India':1380, 'USA':331, 'France':65,'Germany':83, 'Spain':46}
# getting user input
Country_Name = input('Please enter Country Name: ')
# access population using country name from dict
print(population_dict[Country_Name])
population_dict = {'China':123, 'India':231, 'USA':211, 'France':123,'Germany':333, 'Spain':112}
import schedule
import time
# take input initially and setup driver once
Country = input('Enter Country Name: ')
driver = webdriver.Chrome('path/to/chromedriver')
def covid_update():
data_dict = extract_data(Country) # extract fresh data
send_mail(data_dict) # sending email based on the dict
def send_mail_table(data_dict):
# setting mail up
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('email_addr', 'email_pass') # setting login details
# mail body
text = """Data regarding COVID-19 in your country today. Source: https://www.worldometers.info/coronavirus/