编写朋友生日提醒助手,录入朋友生日,联系方式,自动生成生日祝福短信/微信模板,提前提醒生日,还能推荐合适的生日礼物,避免忘记朋友生日,维护友情。

📅 发布时间:2026/7/6 14:44:54 👁️ 浏览次数:
编写朋友生日提醒助手,录入朋友生日,联系方式,自动生成生日祝福短信/微信模板,提前提醒生日,还能推荐合适的生日礼物,避免忘记朋友生日,维护友情。
1. 实际应用场景描述场景小王是一名职场人朋友很多但工作忙碌经常忘记朋友的生日。每次想发祝福时要么太晚要么祝福语千篇一律甚至不知道送什么礼物合适。他希望有一个工具能帮他- 记录朋友的生日和联系方式- 自动生成个性化的生日祝福短信/微信模板- 提前提醒他准备祝福和礼物- 推荐合适的生日礼物避免踩雷痛点- 忘记生日 → 影响友情- 祝福语单调 → 缺乏心意- 礼物选择困难 → 怕不合适- 手动记录麻烦 → 容易丢失2. 核心逻辑讲解1. 录入朋友信息姓名、生日、联系方式、关系2. 祝福语生成根据关系死党/普通朋友/同事生成不同风格的祝福模板3. 礼物推荐根据关系预算推荐礼物类别4. 提前提醒在生日前 N 天提醒用户5. 数据持久化用 JSON 文件存储朋友信息6. 主程序交互菜单式操作方便使用3. 模块化代码结构birthday_helper/│├── main.py # 主程序入口├── friends.py # 朋友信息管理├── blessings.py # 祝福语生成├── gifts.py # 礼物推荐├── reminder.py # 提醒功能├── utils.py # 工具函数└── README.md # 项目说明4. 核心代码实现friends.pyimport jsonimport osFILE friends.jsondef load_friends():if os.path.exists(FILE):with open(FILE, r, encodingutf-8) as f:return json.load(f)return []def save_friends(data):with open(FILE, w, encodingutf-8) as f:json.dump(data, f, ensure_asciiFalse, indent4)def add_friend(name, birthday, contact, relation):friends load_friends()friends.append({name: name, birthday: birthday, contact: contact, relation: relation})save_friends(friends)def list_friends():return load_friends()blessings.pyimport randomTEMPLATES {死党: [兄弟/姐妹生日快乐愿你每天都笑得像今天一样灿烂,认识你是我最大的幸运生日快乐永远年轻],普通朋友: [祝你生日快乐愿你心想事成幸福满满,愿你的每一天都充满阳光与欢笑生日快乐],同事: [祝你生日快乐工作顺利生活愉快,愿你在工作和生活中都能收获满满的幸福]}def generate_blessing(relation):return random.choice(TEMPLATES.get(relation, TEMPLATES[普通朋友]))gifts.pyGIFT_LIST {死党: [定制相册, 手写信, 旅行体验券],普通朋友: [书籍, 香薰蜡烛, 保温杯],同事: [高档笔记本, 桌面绿植, 咖啡礼盒]}def recommend_gift(relation):return GIFT_LIST.get(relation, GIFT_LIST[普通朋友])reminder.pyfrom datetime import datetime, timedeltadef check_upcoming_birthdays(days_before3):today datetime.today()friends __import__(friends).load_friends()for f in friends:bday datetime.strptime(f[birthday], %Y-%m-%d)# 今年生日bday_this_year bday.replace(yeartoday.year)if bday_this_year today:bday_this_year bday_this_year.replace(yeartoday.year 1)days_left (bday_this_year - today).daysif 0 days_left days_before:print(f⏰ 提醒{f[name]} 的生日还有 {days_left} 天)main.pyfrom friends import add_friend, list_friendsfrom blessings import generate_blessingfrom gifts import recommend_giftfrom reminder import check_upcoming_birthdaysdef main():while True:print(\n 朋友生日提醒助手 )print(1. 添加朋友生日)print(2. 查看所有朋友)print(3. 生成祝福语)print(4. 推荐礼物)print(5. 检查近期生日)print(0. 退出)choice input(请选择操作)if choice 1:name input(姓名)birthday input(生日YYYY-MM-DD)contact input(联系方式)relation input(关系死党/普通朋友/同事)add_friend(name, birthday, contact, relation)print(✅ 添加成功)elif choice 2:for f in list_friends():print(f)elif choice 3:name input(朋友姓名)relation input(关系)print(祝福语, generate_blessing(relation))elif choice 4:relation input(关系)print(礼物推荐, recommend_gift(relation))elif choice 5:check_upcoming_birthdays()elif choice 0:breakelse:print(无效选择)if __name__ __main__:main()5. README.md# 朋友生日提醒助手一个帮助您记录朋友生日、生成祝福语、推荐礼物并提前提醒的Python工具。## 功能- 录入朋友生日和联系方式- 自动生成个性化祝福语- 推荐合适的生日礼物- 提前提醒生日## 使用方法1. 安装 Python 3.x2. 运行 python main.py3. 按菜单提示操作## 文件结构- main.py 主程序- friends.py 朋友信息管理- blessings.py 祝福语生成- gifts.py 礼物推荐- reminder.py 提醒功能6. 核心知识点卡片知识点 说明JSON 数据存储 用于持久化朋友信息随机数选择random.choice() 生成多样化祝福日期处理datetime 计算距离生日的天数模块化编程 分文件管理不同功能用户交互 菜单式命令行界面7. 总结这个 朋友生日提醒助手 解决了忘记生日、祝福语单调、礼物选择困难等问题并且通过模块化设计让代码易于维护和扩展。如果你愿意可以在下一步- 增加 微信/短信自动发送 功能调用 API- 做成 桌面 GUI 应用用 Tkinter 或 PyQt- 打包成 Windows 可执行文件利用AI解决实际问题如果你觉得这个工具好用欢迎关注长安牧笛