udemy-100days-code in python-exercise-【24-】

105 阅读1分钟

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)

# 获取鼠标点击的x,y坐标
# def get_mouse_coor(x, y):
#     print(x,y)
# turtle.onscreenclick(get_mouse_coor)

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

  • 关于tkinter GUI 图形

day32 邮件定时发送

  • qq邮件发送
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()