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
+ # message =
31
+ # for i in range(len(title_list)):
32
+ # print(url)
33
+
34
+
35
+ send_mail (
36
+ email_sender = '[email protected] ' ,
37
+ email_receiver = '[email protected] ' ,
38
+ message = f'{ url } ' , #gets rid of brackets
39
+ password = google_p ['password' ],
40
+ subject = 'notification Mail'
41
+ )
42
+
43
+ # print('lets see')
44
+
45
+
46
+ # receivers = ['[email protected] ']
47
+
48
+
49
+ # message = '''from: [email protected]
50
+
51
+ # subject: STMP e-mail test message.
52
+ # '''
53
+
54
+ # try:
55
+ # smtpObj = smtplib.SMTP('localhost')
56
+ # smtpObj.sendmail(sender, receivers, message)
57
+ # print("Successfully sent email")
58
+ # except smtplib.SMTPException:
59
+ # print("Error: unable to send email")
60
+
61
+
62
+
63
+ # smtp_server = "smtp.gmail.com"
64
+ # port = 587 # For starttls
65
+ # sender_email = "[email protected] "
66
+ # password = input("Type your password and press enter: ")
67
+
68
+ # # Create a secure SSL context
69
+ # context = ssl.create_default_context()
70
+
71
+ # # Try to log in to server and send email
72
+ # try:
73
+ # server = smtplib.SMTP(smtp_server,port)
74
+ # # server.ehlo() # Can be omitted
75
+ # server.starttls(context=context) # Secure the connection
76
+ # server.ehlo() # Can be omitted
77
+ # server.login(sender_email, password)
78
+ # # TODO: Send email here
79
+ # except Exception as e:
80
+ # # Print any error messages to stdout
81
+ # print(e)
82
+ # finally:
83
+ # server.quit()
84
+ # json_response_dict = json_response[0]
85
+ # print('first response : ', json_response_dict)
86
+ # title = json_response_dict['title']
87
+ # print('title: ', title)
0 commit comments