Skip to content

Commit 1588e73

Browse files
committed
finished mini
1 parent 3fc40bd commit 1588e73

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import requests
2+
3+
4+
5+
def get_response(page, filter):#matches what it represents
6+
7+
response = requests.get(
8+
f'https://favqs.com/api/quotes' ,
9+
params = {'filter': filter, 'page': page},
10+
headers= {'Authorization': 'Token token="855df50978dc9afd6bf86579913c9f8b"'})#make sure parenthesis and curly brackets are closed
11+
12+
return response
13+
14+
15+
# def get_filter():
16+
# # filter = web['quotes'][0]['body']
17+
# for i in range(len(web)):
18+
# print(web[i]["body"])
19+
20+
21+
22+
# keyword = 'nature' #just to test
23+
24+
25+
# # print(web)
26+
# #
27+
# print('response : ', response) under 41
28+
# print('response text: ', response.text)
29+
# json_response = response.json()['last_page']
30+
31+
# print('response json: ', quotes)#just a variable not a method
32+
# print(quotes['body'])
33+
34+
35+
36+
page = 1
37+
38+
keyword = input('Enter in a keyword: ')
39+
response = get_response(page, keyword) #calling get response fuction with arguments page counter and keyword and setting it equal to web
40+
quotes_dict = response.json()#['quotes'] #<--- thats a type list
41+
42+
while True: #having it repeat until not
43+
44+
for i in range(len(quotes_dict["quotes"])): #looping through the list of the object
45+
46+
47+
#get author from first quote of list
48+
first_quote_dict = quotes_dict['quotes'][i] #accessing item at the key of sequence
49+
first_author = first_quote_dict['author']
50+
#get the quote from the first quote of list
51+
first_quote = first_quote_dict['body']
52+
print(f'\n{first_quote} \n\t\t{first_author}\n')
53+
# json_response = response.json() # makes it
54+
# pprint.pprint('json response: ', json_response)
55+
print(quotes_dict['last_page'])
56+
57+
if quotes_dict['last_page'] != True:
58+
59+
60+
play_again = input('would you like to go to the next page? type y for next page or n for no: ') #command d
61+
if play_again == "y":
62+
page += 1
63+
continue #it goes back up
64+
65+
66+
else:
67+
break
68+
else:
69+
print("You're on the last page")
70+
break
71+
72+
#get keywoed
73+
#get user inputs
74+
#print out quotes
75+
#get response
76+
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+
# 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+
# sender = '[email protected]'
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)

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)