day24 批量写信
name_cl = "[name]"
with open("./222 Mail-Merge-Project-Start/Mail Merge Project Start/Input/Names/invited_names.txt") as f:
names = f.readlines()
with open("./222 Mail-Merge-Project-Start/Mail Merge Project Start/Input/Letters/starting_letter.txt") as letter_file:
letter_contents = letter_file.read()
for name in names:
new_name = name.strip()
new_contents = letter_contents.replace(name_cl,new_name)
with open(f"./222 Mail-Merge-Project-Start/Mail Merge Project Start/Output/letter_{new_name}.txt",mode='w') as completed_letter :
completed_letter.write(new_contents)
day25 地图猜测游戏
import turtle
import pandas
screen = turtle.Screen()
screen.title("game")
img = "blank_states_img.gif"
screen.addshape(img)
turtle.shape(img)
data = pandas.read_csv("test.csv")
all_state = data.state.to_list()
guess_state=[]
while len(guess_state) < 5:
choice = screen.textinput(f"{len(guess_state)}/50", "what's the state's name").title()
if choice in all_state:
guess_state.append(choice)
timmy = turtle.Turtle()
timmy.penup()
timmy.hideturtle()
timmy.goto(int(data[data.state == choice].x),int(data[data.state == choice].y))
timmy.write(choice)
screen.mainloop()
day26 NATO Alphabet -day31
day32 邮件定时发送
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
from_name = "pei"
from_addr = '2410812526@qq.com'
password = 'miymojmtozsgeafh'
to_addr = '2315478928@qq.com'
my_title = 'test'
my_msg = 'hello world'
msg = MIMEText(my_msg,'plain','utf-8')
msg['From'] = formataddr([from_name,from_addr])
msg['Subject'] = my_title
smtp_srv = "smtp.qq.com"
try:
srv = smtplib.SMTP_SSL(smtp_srv.encode(),465)
srv.login(from_addr,password)
srv.sendmail(from_addr,[to_addr],msg.as_string())
print("发送成功")
except Exception as e:
print("发送失败")
finally:
srv.quit()