Guest User

My code

a guest
Nov 28th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. import smtplib
  2.  
  3.  
  4. # Code Link
  5. # https://www.alternativez.info/how-to-send-email-in-python/ --> sending the email code
  6. # https://stackoverflow.com/questions/7232088/python-subject-not-shown-when-sending-email-using-smtplib-module --> Change the subject of the email
  7. # https://www.youtube.com/watch?v=bXRYJEKjqIM --> sending an email
  8.  
  9. user_email = input(" Bot: Please enter the email address that you would like to send an email to: ")
  10.  
  11. print(" ")
  12.  
  13. subject= (input(" Bot: Enter the subject of the email: "))
  14.  
  15. print(" ")
  16.  
  17. body = (input(" Bot: Enter the content of the email: "))
  18.  
  19. print(" ")
  20.  
  21. aemail = input(" Bot: Would you like to send this email to anyone else?\n User: ")
  22.  
  23. x = 'Subject: {}\n\n{}'.format(subject, body)
  24.  
  25. if aemail == "yes" or aemail.upper() == "YES":
  26.  
  27. print(" ")
  28.  
  29. oemail= input("Write the other email --> ")
  30.  
  31. server = smtplib.SMTP('smtp.gmail.com', 587)
  32. server.starttls()
  33.  
  34. # chatbot email login
  35. server.login("chatbottestcu123@gmail.com", "chatbot123")
  36.  
  37. # code to send the email to the user
  38. server.sendmail("chatbottestcu123@gmail.com", user_email, x)
  39. server.sendmail("chatbottestcu123@gmail.com", oemail , x)
  40. server.quit()
  41.  
  42.  
  43. elif aemail.lower() == "no" or aemail.upper()== "N0" :
  44.  
  45. server = smtplib.SMTP('smtp.gmail.com', 587)
  46. server.starttls()
  47.  
  48. server.login("chatbottestmail2@gmail.com", "chatbottest123")
  49. server.sendmail("chatbottestcu123@gmail.com", user_email, x)
  50.  
  51. print(" Bot: Email sent!")
  52.  
  53. server.quit()
  54.  
  55.  
  56.  
  57.  
  58. Shopping List
  59.  
  60.  
  61.  
  62.  
  63. #references
  64.  
  65. # https://www.w3schools.com/python/python_file_handling.asp
  66.  
  67.  
  68.  
  69. file = open( "shoppinglist.txt", "w")
  70. file.write("Your Shopping List : " + "\n")
  71.  
  72. n = int(input("how many items do you want to add ? "))
  73.  
  74. i=0
  75.  
  76. # loop to write the number of items that the user needs
  77.  
  78. for i in range(n):
  79.  
  80. content = str(input("Write your shopping list : "))
  81.  
  82. file.write(content + "\n")
  83.  
  84. if i == n :
  85. break
  86.  
  87. print("")
  88. file = open( "shoppinglist.txt", "r")
  89. print (file.read())
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. Weather and Temperature
  99. import requests
  100.  
  101. # Youtube Tutorials
  102. # https://www.youtube.com/watch?v=lcWfSn6-m_8--> weather api video tutorial
  103. # # https://www.youtube.com/watch?v=PWZKTWJ9bJE --> Temperature in Kelvin
  104. # https://openweathermap.org/ --> weather api website
  105. # https://openweathermap.org/api --> API
  106.  
  107.  
  108. print('')
  109.  
  110. # Weather in Coventry
  111.  
  112. api_address = 'https://api.openweathermap.org/data/2.5/weather?q=Coventry,uk&appid=a283f94f4370e92593315243cecd791b'
  113.  
  114. url = api_address
  115.  
  116. json_data = requests.get(url).json()
  117.  
  118. weatherdesc = json_data['weather'][0]['description']
  119.  
  120. temp = json_data['main']['temp']
  121.  
  122. # Kelvin to Celsius
  123.  
  124. tempc = temp -273.15
  125.  
  126. print('Today is expected in Coventry ' + weatherdesc)
  127.  
  128. print('The temperature is',round(tempc,1),'°C')
  129.  
  130. print('')
  131.  
  132.  
  133. answer = input("Do you wanna know the weather in another place ? ")
  134.  
  135. print('')
  136.  
  137.  
  138. # code for the weather in another city
  139. if answer.lower() == 'yes' or answer.upper() == "YES" :
  140.  
  141. city = input("Enter the name of your city : ")
  142.  
  143. api_address = 'https://api.openweathermap.org/data/2.5/weather?q={}&appid=a283f94f4370e92593315243cecd791b'.format(city)
  144.  
  145. url= api_address
  146.  
  147. json_data = requests.get(url).json()
  148.  
  149. weatherdesc = json_data['weather'][0]['description']
  150.  
  151. temp = json_data['main']['temp']
  152.  
  153. tempc = temp -273.15
  154.  
  155. print('')
  156.  
  157. print('Today is expected in '+ city + ' ' + weatherdesc)
  158. print('The temperature is',round(tempc,1),'°C')
  159.  
  160. print('')
  161.  
  162. elif answer.lower() == 'no' or answer.upper() == "NO" :
  163.  
  164. print('Ok')
Add Comment
Please, Sign In to add comment