Skip to content

Commit b7e3cd7

Browse files
authored
Merge pull request #137 from PdxCodeGuild/andy-mini-capstone
Andy mini capstone completed
2 parents 4068fb6 + 097bc65 commit b7e3cd7

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
import requests
3+
from pywhatkit import send_mail
4+
from important import google_p
5+
6+
7+
def get_response():
8+
response = requests.get('https://api.spaceflightnewsapi.net/v3/articles')
9+
return response
10+
11+
title_list = []
12+
url = []
13+
response = get_response()
14+
json_response = response.json()
15+
# print(json_response)
16+
for i in range(len(json_response)):
17+
spaceflight_title = json_response[i]['title']
18+
spaceflight_url = json_response[i]['url']
19+
20+
21+
title_list.append(spaceflight_title)
22+
url.append(spaceflight_url)
23+
24+
email_msg = []
25+
for i in range(len(url)):
26+
email_msg.append(f"{title_list[i]}\n{url[i]}\n") # combining both list
27+
28+
url = '\n'.join(email_msg) # entire list and joining them in new lines in one string
29+
30+
31+
32+
send_mail(
33+
email_sender = '[email protected]',
34+
email_receiver = '[email protected]',
35+
message = f'{url}',
36+
password = google_p['password'],
37+
subject = 'notification Mail'
38+
)
39+
40+
# print('lets see')
41+
42+
# sender = '[email protected]'
43+
# receivers = ['[email protected]']
44+
45+
46+
# message = '''from: [email protected]
47+
48+
# subject: STMP e-mail test message.
49+
# '''
50+
51+
# try:
52+
# smtpObj = smtplib.SMTP('localhost')
53+
# smtpObj.sendmail(sender, receivers, message)
54+
# print("Successfully sent email")
55+
# except smtplib.SMTPException:
56+
# print("Error: unable to send email")
57+
58+
59+
60+
# smtp_server = "smtp.gmail.com"
61+
# port = 587 # For starttls
62+
# sender_email = "[email protected]"
63+
# password = input("Type your password and press enter: ")
64+
65+
# # Create a secure SSL context
66+
# context = ssl.create_default_context()
67+
68+
# # Try to log in to server and send email
69+
# try:
70+
# server = smtplib.SMTP(smtp_server,port)
71+
# # server.ehlo() # Can be omitted
72+
# server.starttls(context=context) # Secure the connection
73+
# server.ehlo() # Can be omitted
74+
# server.login(sender_email, password)
75+
# # TODO: Send email here
76+
# except Exception as e:
77+
# # Print any error messages to stdout
78+
# print(e)
79+
# finally:
80+
# server.quit()
81+
# json_response_dict = json_response[0]
82+
# print('first response : ', json_response_dict)
83+
# title = json_response_dict['title']
84+
# message =
85+
# for i in range(len(title_list)):
86+
# print(url)
87+
# print('title: ', title)

code/Andy/python/important.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
google_p ={
2+
"password": "khmpragumjlokmnl"}

0 commit comments

Comments
 (0)