Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- # Code Link
- # https://www.alternativez.info/how-to-send-email-in-python/ --> sending the email code
- # https://stackoverflow.com/questions/7232088/python-subject-not-shown-when-sending-email-using-smtplib-module --> Change the subject of the email
- # https://www.youtube.com/watch?v=bXRYJEKjqIM --> sending an email
- user_email = input(" Bot: Please enter the email address that you would like to send an email to: ")
- print(" ")
- subject= (input(" Bot: Enter the subject of the email: "))
- print(" ")
- body = (input(" Bot: Enter the content of the email: "))
- print(" ")
- aemail = input(" Bot: Would you like to send this email to anyone else?\n User: ")
- x = 'Subject: {}\n\n{}'.format(subject, body)
- if aemail == "yes" or aemail.upper() == "YES":
- print(" ")
- oemail= input("Write the other email --> ")
- server = smtplib.SMTP('smtp.gmail.com', 587)
- server.starttls()
- # chatbot email login
- server.login("chatbottestcu123@gmail.com", "chatbot123")
- # code to send the email to the user
- server.sendmail("chatbottestcu123@gmail.com", user_email, x)
- server.sendmail("chatbottestcu123@gmail.com", oemail , x)
- server.quit()
- elif aemail.lower() == "no" or aemail.upper()== "N0" :
- server = smtplib.SMTP('smtp.gmail.com', 587)
- server.starttls()
- server.login("chatbottestmail2@gmail.com", "chatbottest123")
- server.sendmail("chatbottestcu123@gmail.com", user_email, x)
- print(" Bot: Email sent!")
- server.quit()
- Shopping List
- #references
- # https://www.w3schools.com/python/python_file_handling.asp
- file = open( "shoppinglist.txt", "w")
- file.write("Your Shopping List : " + "\n")
- n = int(input("how many items do you want to add ? "))
- i=0
- # loop to write the number of items that the user needs
- for i in range(n):
- content = str(input("Write your shopping list : "))
- file.write(content + "\n")
- if i == n :
- break
- print("")
- file = open( "shoppinglist.txt", "r")
- print (file.read())
- Weather and Temperature
- import requests
- # Youtube Tutorials
- # https://www.youtube.com/watch?v=lcWfSn6-m_8--> weather api video tutorial
- # # https://www.youtube.com/watch?v=PWZKTWJ9bJE --> Temperature in Kelvin
- # https://openweathermap.org/ --> weather api website
- # https://openweathermap.org/api --> API
- print('')
- # Weather in Coventry
- api_address = 'https://api.openweathermap.org/data/2.5/weather?q=Coventry,uk&appid=a283f94f4370e92593315243cecd791b'
- url = api_address
- json_data = requests.get(url).json()
- weatherdesc = json_data['weather'][0]['description']
- temp = json_data['main']['temp']
- # Kelvin to Celsius
- tempc = temp -273.15
- print('Today is expected in Coventry ' + weatherdesc)
- print('The temperature is',round(tempc,1),'°C')
- print('')
- answer = input("Do you wanna know the weather in another place ? ")
- print('')
- # code for the weather in another city
- if answer.lower() == 'yes' or answer.upper() == "YES" :
- city = input("Enter the name of your city : ")
- api_address = 'https://api.openweathermap.org/data/2.5/weather?q={}&appid=a283f94f4370e92593315243cecd791b'.format(city)
- url= api_address
- json_data = requests.get(url).json()
- weatherdesc = json_data['weather'][0]['description']
- temp = json_data['main']['temp']
- tempc = temp -273.15
- print('')
- print('Today is expected in '+ city + ' ' + weatherdesc)
- print('The temperature is',round(tempc,1),'°C')
- print('')
- elif answer.lower() == 'no' or answer.upper() == "NO" :
- print('Ok')
Add Comment
Please, Sign In to add comment