Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import smtplib, ssl, sys #from https://realpython.com/python-send-email/
from newsapi import NewsApiClient
import requests
from random import randint
import random
subscribers=["uttejsng@gmail.com","anumoluu@coventry.ac.uk","anumoluuthejkumar@gmail.com","kummymorla@gmail.com"]
newsapi = NewsApiClient(api_key='8fd6fd600d9642659c6e41ebea960aa7') #from https://newsapi.org/docs/client-libraries/python
top_headlines = newsapi.get_top_headlines(q=None, #from https://newsapi.org/docs/client-libraries/python
sources=None,
category='business',
language='en',
country='gb')
sources = newsapi.get_sources()
def headlines():
x=randint(0,15)
y=x+5
headlines=""
for i in range(x,y):
headlines=headlines+"\n"+top_headlines['articles'][i]['title']+"\n"+top_headlines['articles'][i]['url'] #from https://newsapi.org/docs/client-libraries/python
return headlines
def create_message():
message = """\
Today's News
Here are your articles:\n""" + headlines() +""""""
return message
def send_email():
password = input("Type your password and press enter:")
for receiver_email in subscribers: #from https://realpython.com/python-send-email/
port = 465 # For SSL
smtp_server = "smtp.gmail.com"
sender_email = "throwaway7789836353@gmail.com" # Enter your address
message = create_message()
context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message.encode('utf-8'))
def main():
while(1==1):
option= input("Welcome! What would you like to do today? \nIf you want to send the email to the current subscribers'list, press 1 \nIf you want to add to the list, press 2 \nIf you want to delete from the list, press 3 \nIf you want to exit, press 4 ")
if option=="1":
send_email()
sys.exit(0)
elif option=="2":
x=input("Enter the email you want to add")
subscribers.append(x)
elif option=="3":
y=input("Enter the email you want to delete")
try:
subscribers.remove(y)
except ValueError:
print("please enter a proper value")
elif option=="4":
sys.exit(0)
else:
print("please enter a proper value")
if __name__=="__main__":
main()