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?
re_sit4006/data.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
60 lines (56 sloc)
3.41 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
def check_mail(mail):#check the email if there is in file | |
there_is_mail=False # when we start the research do not know if the email there is in the file txt | |
with open('mails.txt') as f:# open the file as "f" | |
if mail in f.read():# checking for email | |
there_is_mail=True #is means we found the email | |
elif mail not in f.read():#checking if the email is different if yes them | |
there_is_mail=False# we did not found the email | |
return there_is_mail# return if the email there is here or not | |
#I would like to thank the following site for the help it provides me | |
# # https://www.codegrepper.com/search.php?q=how%20to%20find%20string%20in%20text%20file%20using%20python | |
def write_mail(mail):#check if email these is in file and them w | |
there_is_mail=False#when we start the research do not know if the email there is in the file txt | |
file=open("mails.txt","r")# name of the file ,the reason why we need to open. r is means read | |
with open('mails.txt') as f:# open the file as "f" | |
if mail in f.read():# checking for email | |
there_is_mail=True# is means we found the email | |
#I would like to thank the following site for the help it provides me | |
# https://www.codegrepper.com/search.php?q=how%20to%20find%20string%20in%20text%20file%20using%20python | |
file.close() # close the file | |
if there_is_mail==False:#the emails there isn't in file txt | |
File = open("mails.txt", "a")#name of the file ,the reason why we need to open. a is means append | |
File.write(mail+"\n")#write emails in file txt and spece for next email | |
File.close()# close the file | |
there_is_mail=True# is means we wrote the email | |
return there_is_mail# return what happened to the email | |
#I would like to thank the following site for the help it provides me | |
# https://www.codegrepper.com/search.php?q=write%20line%20in%20text%20file%20python | |
def delete_mail(mail):#delete the line with mail (delete the mail from database) | |
with open("mails.txt", "r") as f:#first, open the file for reader to know what has inside | |
lines = f.readlines()#read line by ine | |
with open("mails.txt", "w") as f:#name of the file ,the reason why we need to open. w is means write | |
for line in lines:# we prepare to write line by line | |
if line.strip("\n") != mail: #check if the email is different from the email we want to delete if yes then | |
f.write(line)#write the email | |
#I would like to thank the following site for the help it provides me | |
# https://www.codegrepper.com/search.php?q=delete%20line%20in%20text%20file%20python | |
def read_the_data_base():#Using readlines() | |
print("these are mails we have in the database:") | |
file1 = open('mails.txt', 'r')#name of the file, the reason why we need to open. r is means read | |
Lines = file1.readlines() | |
count = 0 | |
for line in Lines:#print line by line what did you read | |
count += 1 | |
print(format( line.strip())) # printing | |
#I would like to thank the following site for the help it provides me | |
# https://www.geeksforgeeks.org/read-a-file-line-by-line-in-python/ (Example 3) | |
def sender(mail): | |
import smtplib | |
import ssl | |
from printers import message | |
server = smtplib.SMTP_SSL("smtp.gmail.com",465)#(server address,portal number ) | |
server.login("tipotanothing@gmail.com" , "tipota1345")#(email,password ) | |
server.sendmail("tipotanothing@gmail.com",mail,message)#(the sender,the receiver,) | |
#server.quit() | |
#I would like to thank the following site for the help it provides me | |
#https://www.tutorialspoint.com/python/python_sending_email.htm |