Permalink
Cannot retrieve contributors at this time
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?
4006_deffer_project-email/tools.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
164 lines (92 sloc)
3.47 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
import random | |
import schedule | |
import time | |
import requests | |
class email_client: # declaring class | |
def __init__(self,email_id,options,subf): | |
self.email_id=email_id | |
self.options=options | |
self.subf=subf | |
def email_sending(email_id,x): #verification code sending function | |
ste = str(x) | |
ad_email='4006.projectd@gmail.com' | |
ad_pass='4006email' | |
server = smtplib.SMTP_SSL("smtp.gmail.com", 465) | |
server.login(ad_email, ad_pass) | |
server.sendmail(ad_email, email_id,ste) #sending email | |
server.quit() | |
return 0 | |
def verification(email_id): #verification code generating function | |
r=0 | |
ran= random.randint(100000,1000000) #generating random numbers | |
x=int(ran) | |
email_client.email_sending(email_id,x) #calling verification code sending function | |
while r <= 10: | |
otp = input("please enter the verification code form mail (check spam)") | |
inp=0 | |
inp=int(otp) | |
if (x == inp): #verifying | |
print("the email have been verified") | |
r=11 | |
return 1 | |
else: | |
print('sorry email not verified') | |
print("try again") | |
r=r+1 | |
return 0 | |
def email_frequency(subf): #scheduling function | |
if(subf=="1"): | |
schedule.every().minute.do(sch) # for every minute | |
while 1: | |
schedule.run_pending() | |
time.sleep(1) | |
elif(subf==2): | |
schedule.every().hour.do(sch) #for every hour | |
while 1: | |
schedule.run_pending() | |
time.sleep(1) | |
elif(subf==3): | |
schedule.every().day.do(sch) #for every day | |
while 1: | |
schedule.run_pending() | |
time.sleep(1) | |
elif(subf==4): | |
schedule.every().monday.do(sch) #for every week | |
while 1: | |
schedule.run_pending() | |
time.sleep(1) | |
def email_content(email_id,content): #function for sending content | |
#subject = 'options' | |
ad_email = '4006.projectd@gmail.com' | |
ad_pass = '4006email' | |
#content1=str(content) | |
#message='Subject:{}\n\n'.format(subject,content1) | |
server = smtplib.SMTP_SSL("smtp.gmail.com", 465) | |
server.login(ad_email,ad_pass) | |
server.sendmail(ad_email, email_id,content) | |
print("mail sent") | |
server.quit() | |
return 0 | |
def api_content(options): #function for obtaining api_content | |
url = "https://free-news.p.rapidapi.com/v1/search" | |
qstring = {"q": options, "lang": "en"} | |
keys = { | |
'x-rapidapi-key': "8797cd37f4mshde4d4feba357c0dp1ec941jsnd0e8ab928355", | |
'x-rapidapi-host': "free-news.p.rapidapi.com" | |
} | |
response = requests.get(url, headers=keys, params=qstring).json() | |
w=response['articles'] | |
n=random.randint(0,10) | |
x=w[n] | |
t=str(x['summary']) | |
u=str(x['title']) | |
v = str(x['clean_url']) | |
w=str(x['published_date']) | |
y=str(x['link']) | |
f =u+"\n\n\n\n"+w +'\n\n\n\n\n' +t+ "\n\n\n\n"+y | |
return f | |
def sch(): #for sending | |
content = email_client.api_content(email_client.options) | |
email_client.email_content(email_client.email_id, content) | |
return 0 | |