diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..44db8ec --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# 忽略 IDE 配置文件 +.idea/ +.vscode/ + +# 忽略 __pycache__ 文件夹 +**/__pycache__/ + +# 忽略 Jupyter Notebook 文件 +*.ipynb diff --git a/conf.yaml b/conf.yaml new file mode 100644 index 0000000..3ef1b9c --- /dev/null +++ b/conf.yaml @@ -0,0 +1,26 @@ +# 爬虫相关配置 +spider_settings: + enable: false # 是否启用爬虫 + json_url: "https://blog.qyliu.top/friend.json" # 请填写对应格式json的地址,仅支持网络地址 + article_count: 5 # 请填写每个博客需要获取的最大文章数量 + +# 邮箱推送功能配置,还没实现 +email_push: + enable: false # 是否启用邮箱推送功能 + to_email: recipient@example.com # 收件人邮箱地址 + subject: "今天的 RSS 订阅更新" # 邮件主题 + body_template: "rss_template.html" # 邮件正文的 HTML 模板文件 + +# 邮箱issue订阅功能配置 +rss_subscribe: + enable: true # 是否启用邮箱推送功能 + github_username: willow-god # GitHub 用户名 + github_repo: Friend-Circle-Lite # GitHub 仓库名 + your_blog_url: https://blog.qyliu.top/ # 你的博客地址 + +# SMTP 配置 +smtp: + email: 3162475700@qq.com # 发件人邮箱地址 + server: smtp.qq.com # SMTP 服务器地址 + port: 587 # SMTP 端口号 + use_tls: true # 是否使用 tls 加密 diff --git a/conf.yml b/conf.yml deleted file mode 100644 index 58a4e35..0000000 --- a/conf.yml +++ /dev/null @@ -1,23 +0,0 @@ -# 爬虫相关配置 -spider_settings: - enable: true # 是否启用爬虫 - json_url: "https://blog.qyliu.top/friend.json" # 请填写对应格式json的地址,仅支持网络地址 - article_count: 5 # 请填写每个博客需要获取的最大文章数量 - -# 邮箱推送功能配置 -email_push: - enabled: true # 是否启用邮箱推送功能 - to_email: recipient@example.com # 收件人邮箱地址 - subject: "今天的 RSS 订阅更新" # 邮件主题 - body_template: "rss_template.html" # 邮件正文的 HTML 模板文件 - -# SMTP 配置 -smtp: - email: your_email@example.com # 发件人邮箱地址 - server: smtp.example.com # SMTP 服务器地址 - port: 587 # SMTP 端口号 - use_tls: true # 是否使用 TLS 加密 - username: your_smtp_username # SMTP 用户名 - password: your_smtp_password # SMTP 密码 - - diff --git a/dev_test/last_articles.json b/dev_test/last_articles.json deleted file mode 100644 index e5ea8d0..0000000 --- a/dev_test/last_articles.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "articles": [ - { - "title": "东软软件园实习日记", - "author": "", - "link": "https://blog.qyliu.top/posts/13e6e155/", - "published": "2024-07-01 08:39", - "summary": "大学生累成狗,今天我终于理解了为什么这么说,好不容易结束了为期七天的实训课程,又要写实验报告加小组作业,好不容易完成了小组作业,这不,十五天实习又来了!烦!并且还要天天写学习日志?我直接当作日记写好不好!", - "content": "大学生累成狗,今天我终于理解了为什么这么说,好不容易结束了为期七天的实训课程,又要写实验报告加小组作业,好不容易完成了小组作业,这不,十五天实习又来了!烦!并且还要天天写学习日志?我直接当作日记写好不好!" - }, - { - "title": "Github Action实现友链状态检测", - "author": "", - "link": "https://blog.qyliu.top/posts/c2262998/", - "published": "2024-06-23 17:00", - "summary": "随着友情链接数量的增加,人工检测变得繁琐,我最初尝试通过爬取数据进行检测,但数据更新滞后。在群友安小歪的启发下,我采用了GitHub Action自动运行检测脚本,比较有效实现了友链有效性的自动化监测,同时将数据展示在了友情链接页面中,除此之外,原有的摸鱼页面也被我整合到了友链朋友圈页面中。", - "content": "随着友情链接数量的增加,人工检测变得繁琐,我最初尝试通过爬取数据进行检测,但数据更新滞后。在群友安小歪的启发下,我采用了GitHub Action自动运行检测脚本,比较有效实现了友链有效性的自动化监测,同时将数据展示在了友情链接页面中,除此之外,原有的摸鱼页面也被我整合到了友链朋友圈页面中。" - }, - { - "title": "安全跳转页面·插件版", - "author": "", - "link": "https://blog.qyliu.top/posts/1dfd1f41/", - "published": "2024-06-16 17:00", - "summary": "经过两个月的努力,我终于找到了完美的外链跳转解决方案!初始版本使用外置JS存在诸多bug,如图片灯箱、友链和站内跳转链接等问题。经过一段时间的学习和代码调整,我取得了阶段性进展,现在能够实现各种所需功能。最近,我在hexo-external-link插件的基础上进行了底层重构,最终实现了真正的插件版外链替换,不再依赖JS,功能更加完善,且使用更加方便!", - "content": "经过两个月的努力,我终于找到了完美的外链跳转解决方案!初始版本使用外置JS存在诸多bug,如图片灯箱、友链和站内跳转链接等问题。经过一段时间的学习和代码调整,我取得了阶段性进展,现在能够实现各种所需功能。最近,我在hexo-external-link插件的基础上进行了底层重构,最终实现了真正的插件版外链替换,不再依赖JS,功能更加完善,且使用更加方便!" - }, - { - "title": "Alist宝塔部署及其美化", - "author": "", - "link": "https://blog.qyliu.top/posts/a84f5e47/", - "published": "2024-06-04 11:24", - "summary": "Alist 是一个轻量级的目录列表程序,可以用于管理文件索引。将 Alist 部署在宝塔面板中,并进行美化,可以提升用户体验。在本教程中,将介绍我的部署经过,并给出相应的美化代码。", - "content": "Alist 是一个轻量级的目录列表程序,可以用于管理文件索引。将 Alist 部署在宝塔面板中,并进行美化,可以提升用户体验。在本教程中,将介绍我的部署经过,并给出相应的美化代码。" - }, - { - "title": "计算机网络期末总复习", - "author": "", - "link": "https://blog.qyliu.top/posts/8dfa25e1/", - "published": "2024-05-30 16:48", - "summary": "应该注意到标题的改变了吧,本来是一章节一章节的复习,奈何我突然发现,老师画的重点和考研的重点并不是很符合,没办法咯,于是我决定将计算机网络考研复习部分的内容暂时搁置,后面逐步更新,反正一定是会更新的,因为408必考呀!然后将期末复习内容先整理出来,按照老师的考点进行复习。", - "content": "应该注意到标题的改变了吧,本来是一章节一章节的复习,奈何我突然发现,老师画的重点和考研的重点并不是很符合,没办法咯,于是我决定将计算机网络考研复习部分的内容暂时搁置,后面逐步更新,反正一定是会更新的,因为408必考呀!然后将期末复习内容先整理出来,按照老师的考点进行复习。" - } - ] -} \ No newline at end of file diff --git a/dev_test/main.ipynb b/dev_test/main.ipynb deleted file mode 100644 index f2d672b..0000000 --- a/dev_test/main.ipynb +++ /dev/null @@ -1,287 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "正在检查 清羽飞扬 的博客 https://blog.qyliu.top/\n", - "正在检查 张洪Heo 的博客 https://blog.zhheo.com/\n", - "正在检查 Leonus 的博客 https://blog.leonus.cn/\n", - "正在检查 杜老师说 的博客 https://dusays.com\n", - "一府 的博客 https://blog.duolaa.asia/ 无法访问\n", - "正在检查 贰猹 的博客 https://noionion.top/\n", - "正在检查 ChrisKim 的博客 https://www.zouht.com/\n", - "正在检查 無名小栈 的博客 https://blog.imsyy.top/\n", - "正在检查 满心记 的博客 https://blog.lovelu.top/\n", - "正在检查 Tianli 的博客 https://tianli-blog.club/\n", - "不可链接的FEED地址:https://blog.imsyy.top/atom.xml: HTTPSConnectionPool(host='blog.imsyy.top', port=443): Max retries exceeded with url: /404 (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))\n", - "正在检查 Akilar 的博客 https://akilar.top/\n", - "正在检查 星港Star 的博客 https://blog.starsharbor.com\n", - "清风 的博客 https://luckqf.cn 无法访问\n", - "dreamChaser 的博客 https://blog.wenjing.xin/ 无法访问\n", - "正在检查 百里飞洋 的博客 https://blog.meta-code.top/\n", - "正在检查 揽星 的博客 https://lanxing.net/\n", - "正在检查 Android 的博客 https://android99.com\n", - "正在检查 阮一峰 的博客 https://www.ruanyifeng.com/blog/\n", - "正在检查 星辰日记 的博客 https://blog.xsot.cn/\n", - "正在检查 星の野 的博客 https://byer.top/\n", - "正在检查 June 的博客 https://blog.june-pj.cn/\n", - "正在检查 幻雪博客 的博客 https://huanxueblog.top/\n", - "正在检查 风记星辰 的博客 https://www.thyuu.com\n", - "正在检查 呓语梦轩 的博客 https://blog.awaae001.top\n", - "正在检查 青桔气球 的博客 https://blog.qjqq.cn/\n", - "AlenLiu 的博客 https://blog.alenliu.space/ 无法访问\n", - "正在检查 山岳库博 的博客 https://kmar.top/\n", - "JackieZhu 的博客 https://blog.zhfan.top/ 无法访问\n", - "正在检查 微霞 的博客 https://yuuu.org\n", - "Redish 的博客 https://blog.redish101.top/ 无法访问\n", - "Rootlex 的博客 https://blog.nalex.top 无法访问\n", - "GuKaifeng 的博客 https://gukaifeng.cn/ 无法访问\n", - "正在检查 乙未博客 的博客 https://www.yvii.cn\n", - "正在检查 东评西就 的博客 https://dongjunke.cn\n", - "正在检查 Fgaoxing 的博客 https://www.yt-blog.top/\n", - "正在检查 鹊楠 的博客 https://www.quenan.love\n", - "正在检查 Ariasaka 的博客 https://blog.yaria.top/\n", - "理随 的博客 https://lisui.top/ 无法访问\n", - "听风小屋 的博客 https://blog.ifeng.asia/ 无法访问\n", - "正在检查 半方池水 的博客 https://uuanqin.top/\n", - "正在检查 往日信笺 的博客 https://www.xingmail.cn/\n", - "正在检查 皮普 的博客 https://pipuwong.com\n", - "正在检查 luo 的博客 https://www.bokelhc.cn\n", - "正在检查 星空故事 的博客 https://blog.sinzmise.top/\n", - "正在检查 刘郎阁 的博客 https://yjvc.cn/index.php/\n", - "正在检查 obaby 的博客 https://h4ck.org.cn/\n", - "正在检查 湘铭 的博客 https://xiangming.site/\n", - "正在检查 爱吃肉的猫 的博客 https://meuicat.com/\n", - "青竹小轩 的博客 https://gyhwd.top/ 无法访问\n", - "正在检查 星辰 的博客 https://blog.6ing.top/\n", - "正在检查 辞琼 的博客 https://blog.wsq127.top/\n", - "正在检查 Efu 的博客 https://www.efu.me/\n", - "正在检查 茗辰原 的博客 https://mingcy.xyz/\n", - "正在检查 葱苓sama 的博客 https://blog.ciraos.top/\n", - "Fiveth 的博客 https://blog.fiveth.cc/ 无法访问\n", - "正在检查 HiPeach 的博客 https://blog.opeach.cn\n", - "微笔记 的博客 https://flytusky.top 无法访问\n", - "正在检查 微生之最 的博客 https://www.bbixb.top/\n", - "正在检查 蛋蛋困了 的博客 https://blog.wzwzx.cn/\n", - "正在检查 凉心 的博客 https://www.lxink.cn/\n", - "正在检查 陌颜Hao 的博客 https://blog.imoyan.top/\n", - "正在检查 M.Talen 的博客 https://blog.talen.top/\n", - "正在检查 轻笑 的博客 https://www.qcqx.cn/\n", - "正在检查 虹墨 的博客 https://www.imaegoo.com/\n", - "正在检查 痕迹小站 的博客 https://www.henjinet.com/\n", - "Dreamaker 的博客 http://dreamakerr.cn/ 无法访问\n", - "正在检查 纸鹿本鹿 的博客 https://blog.zhilu.cyou\n", - "SerMs 的博客 https://blog.serms.top/ 无法访问\n", - "正在检查 XINGYE 的博客 https://blog.xing-ye.top/\n", - "GanSer 的博客 https://www.gan1ser.top/ 无法访问\n", - "正在检查 六月是只猫 的博客 https://www.lyszm.com/\n", - "正在检查 凌云 的博客 https://www.linyunlink.top/\n", - "ZHI-BLOG 的博客 https://blog.zhwei.tech/ 无法访问\n", - "正在检查 BUZZ 的博客 https://blog.buzzchat.top/\n", - "正在检查 云晓晨 的博客 https://www.catchyxc.com/\n", - "安知鱼 的博客 https://blog.anheyu.com/ 无法访问\n", - "正在检查 唐志远 的博客 https://fe32.top/\n", - "数据处理完成\n", - "总共有 77 位朋友,其中 59 位博客可访问,18 位博客无法访问\n" - ] - } - ], - "source": [ - "# 引入 check_feed 和 parse_feed 函数\n", - "from friend_circle_lite.get_info import fetch_and_process_data\n", - "import json\n", - "\n", - "result = fetch_and_process_data(\"https://blog.qyliu.top/friend.json\")\n", - "\n", - "# 将结果保存为 JSON 文件\n", - "with open(\"result.json\", \"w\", encoding=\"utf-8\") as f:\n", - " json.dump(result, f, ensure_ascii=False, indent=2)" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['atom', 'https://www.linyunlink.top/atom.xml']\n", - "不可链接的FEED地址:['atom', 'https://www.linyunlink.top/atom.xml']: No connection adapters were found for \"['atom', 'https://www.linyunlink.top/atom.xml']\"\n", - "{'website_name': '', 'author': '', 'link': '', 'articles': []}\n" - ] - } - ], - "source": [ - "from friend_circle_lite.get_info import check_feed, parse_feed\n", - "\n", - "url = check_feed(\"https://www.linyunlink.top/\")\n", - "print(url)\n", - "feed = parse_feed(url)\n", - "print(feed)" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "from friend_circle_lite.get_info import sort_articles_by_time\n", - "\n", - "sorted_result = sort_articles_by_time(result)\n", - "\n", - "# 将结果保存为 JSON 文件\n", - "with open(\"result.json\", \"w\", encoding=\"utf-8\") as f:\n", - " json.dump(sorted_result, f, ensure_ascii=False, indent=2)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'website_name': '张洪Heo', 'author': '', 'link': 'https://blog.zhheo.com/', 'articles': [{'title': '新配了一个专门玩英雄联盟的台式机主机,分享下配置和过程', 'author': '', 'link': 'https://blog.zhheo.com/p/9a18f6bb.html', 'published': '2024-06-20 01:55', 'summary': '

我只玩英雄联盟这一个网游,之前一直在用我淘汰下来的MacBook Pro 2019 intel i7', 'content': '

我只玩英雄联盟这一个网游,之前一直在用我淘汰下来的MacBook Pro 2019 intel i7'}, {'title': '解决iOS邮箱使用QQ邮箱账户无法发送邮件,连接发信服务器失败问题', 'author': '', 'link': 'https://blog.zhheo.com/p/cb3f5ed0.html', 'published': '2024-06-20 01:53', 'summary': '

我最近从qq邮箱换到了iOS自带的邮件客户端,一方面是因为自从qq邮箱出了会员之后一堆广告,一方面就是iOS18将支持邮件筛选,我也想用用。但是使用QQ邮箱连接会有一些问题。

\\n

一方面是需要授权码验证,这个大家都比较清楚,登录的密码不是你的qq密码,而是qq邮箱', 'content': '

我最近从qq邮箱换到了iOS自带的邮件客户端,一方面是因为自从qq邮箱出了会员之后一堆广告,一方面就是iOS18将支持邮件筛选,我也想用用。但是使用QQ邮箱连接会有一些问题。

\\n

一方面是需要授权码验证,这个大家都比较清楚,登录的密码不是你的qq密码,而是qq邮箱'}, {'title': '要排除的文件已经被上传到远程Git仓库怎么办', 'author': '', 'link': 'https://blog.zhheo.com/p/faf797ab.html', 'published': '2024-06-19 09:43', 'summary': '

mac有个毒瘤文件就是DS_Store,如果没有全局排除掉那么上传新项目的时候很容易就被上传。还有一些其他的构建文件如果没有设置好.gitignore也会被上传。

\\n

有的时候排除文件在我们项目过一段时间后才想起来添加,但是那时候远程库已', 'content': '

mac有个毒瘤文件就是DS_Store,如果没有全局排除掉那么上传新项目的时候很容易就被上传。还有一些其他的构建文件如果没有设置好.gitignore也会被上传。

\\n

有的时候排除文件在我们项目过一段时间后才想起来添加,但是那时候远程库已'}, {'title': 'Mac安装java17(openjdk@17)支持M系列芯片和intel芯片', 'author': '', 'link': 'https://blog.zhheo.com/p/6243d392.html', 'published': '2024-06-17 02:46', 'summary': '

因为入坑Halo插件开发,装环境研究了一个多小时。主要是错误的安装了版本。Halo的java版本要求是17,这个教程介绍安装java17,通过homebrew来进行安装,然后添加链接即可。

\\n

因为入坑Halo插件开发,装环境研究了一个多小时。主要是错误的安装了版本。Halo的java版本要求是17,这个教程介绍安装java17,通过homebrew来进行安装,然后添加链接即可。

\\n

Vision Pro 已经支持了中国大陆销售,售价29999。当然这不是重点,主要Vision', 'content': '

Vision Pro 已经支持了中国大陆销售,售价29999。当然这不是重点,主要Vision'}]}\n" - ] - } - ], - "source": [ - "from friend_circle_lite.get_info import fetch_and_process_data, check_feed, parse_feed\n", - "\n", - "print(parse_feed(check_feed(\"https://blog.zhheo.com/\")[-1]))" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "python-dateutil 版本: 2.8.2\n", - "requests 版本: 2.31.0\n", - "feedparser 版本: 6.0.11\n" - ] - } - ], - "source": [ - "import datetime\n", - "import dateutil\n", - "import requests\n", - "import feedparser\n", - "\n", - "# 打印 datetime 包的版本\n", - "\n", - "# 打印 python-dateutil 包的版本\n", - "print(f\"python-dateutil 版本: {dateutil.__version__}\")\n", - "\n", - "# 打印 requests 包的版本\n", - "print(f\"requests 版本: {requests.__version__}\")\n", - "\n", - "# 打印 feedparser 包的版本\n", - "print(f\"feedparser 版本: {feedparser.__version__}\")\n" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "# 将系统路径设置为../\n", - "import sys\n", - "sys.path.append(\"../\")" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{\n", - " \"emails\": [\n", - " \"3162475700@qq.com\"\n", - " ]\n", - "}\n" - ] - } - ], - "source": [ - "from rss_subscribe.push_article_update import extract_emails_from_issues\n", - "import json\n", - "\n", - "api_url = \"https://api.github.com/repos/willow-god/Friend-Circle-Lite/issues\"\n", - "emails = extract_emails_from_issues(api_url)\n", - "print(json.dumps(emails, indent=2))" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "从 https://blog.qyliu.top/ 获取到 5 篇文章,其中 0 篇为新文章\n", - "None\n" - ] - } - ], - "source": [ - "from rss_subscribe.push_article_update import get_latest_articles_from_link\n", - "import json\n", - "\n", - "url = \"https://blog.qyliu.top/\"\n", - "articles = get_latest_articles_from_link(url, last_articles_path=\"../rss_subscribe/last_articles.json\")\n", - "print(articles)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "base", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/friend_circle_lite/__pycache__/__init__.cpython-311.pyc b/friend_circle_lite/__pycache__/__init__.cpython-311.pyc index d0d0852..995bb7a 100644 Binary files a/friend_circle_lite/__pycache__/__init__.cpython-311.pyc and b/friend_circle_lite/__pycache__/__init__.cpython-311.pyc differ diff --git a/friend_circle_lite/__pycache__/__init__.cpython-312.pyc b/friend_circle_lite/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index 41bd267..0000000 Binary files a/friend_circle_lite/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/friend_circle_lite/__pycache__/get_conf.cpython-312.pyc b/friend_circle_lite/__pycache__/get_conf.cpython-312.pyc deleted file mode 100644 index c4a7df1..0000000 Binary files a/friend_circle_lite/__pycache__/get_conf.cpython-312.pyc and /dev/null differ diff --git a/friend_circle_lite/__pycache__/get_info.cpython-311.pyc b/friend_circle_lite/__pycache__/get_info.cpython-311.pyc index 0edce97..ead2e1a 100644 Binary files a/friend_circle_lite/__pycache__/get_info.cpython-311.pyc and b/friend_circle_lite/__pycache__/get_info.cpython-311.pyc differ diff --git a/friend_circle_lite/__pycache__/get_info.cpython-312.pyc b/friend_circle_lite/__pycache__/get_info.cpython-312.pyc deleted file mode 100644 index b3cc621..0000000 Binary files a/friend_circle_lite/__pycache__/get_info.cpython-312.pyc and /dev/null differ diff --git a/push_rss_update/send_email.py b/push_rss_update/send_email.py index e69de29..78a0ba5 100644 --- a/push_rss_update/send_email.py +++ b/push_rss_update/send_email.py @@ -0,0 +1,67 @@ +import smtplib +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText + +def email_sender( + target_email, + sender_email, + smtp_server, + port, + password, + subject, + body, + use_tls=True, + ): + """ + 发送电子邮件。 + + 参数: + target_email (str): 目标邮箱地址。 + sender_email (str): 发信邮箱地址。 + smtp_server (str): SMTP 服务地址。 + port (int): SMTP 服务端口。 + use_ssl (bool): 是否使用 SSL 加密。 + username (str): SMTP 服务用户名。 + password (str): SMTP 服务密码。 + subject (str): 邮件主题。 + body (str): 邮件内容。 + """ + # 创建 MIME 对象 + msg = MIMEMultipart() + msg['From'] = sender_email + msg['To'] = target_email + msg['Subject'] = subject + + # 添加邮件内容 + msg.attach(MIMEText(body, 'plain')) + + # 连接到 SMTP 服务器并发送邮件 + try: + with smtplib.SMTP(smtp_server, port) as server: + if use_tls: + server.starttls() # 启动安全模式 + server.login(sender_email, password) + server.sendmail(sender_email, target_email, msg.as_string()) + print(f'邮件已发送到 {target_email}') + except Exception as e: + print(f'无法发送邮件到 {target_email}. 错误: {e}') + +def send_emails(emails, sender_email, smtp_server, port, password, subject, body, use_tls=True): + """ + 循环发送邮件给指定的多个邮箱。 + + 参数: + emails (list): 包含目标邮箱地址的列表。 + sender_email (str): 发信邮箱地址。 + smtp_server (str): SMTP 服务地址。 + port (int): SMTP 服务端口。 + password (str): SMTP 服务密码。 + subject (str): 邮件主题。 + body (str): 邮件内容。 + use_tls (bool): 是否使用 TLS 加密,默认为 True。 + """ + for email in emails: + email_sender(email, sender_email, smtp_server, port, password, subject, body, use_tls) + + + diff --git a/rss_subscribe/__pycache__/__init__.cpython-311.pyc b/rss_subscribe/__pycache__/__init__.cpython-311.pyc index 188f927..70b25b5 100644 Binary files a/rss_subscribe/__pycache__/__init__.cpython-311.pyc and b/rss_subscribe/__pycache__/__init__.cpython-311.pyc differ diff --git a/rss_subscribe/__pycache__/push_article_update.cpython-311.pyc b/rss_subscribe/__pycache__/push_article_update.cpython-311.pyc index 600191d..08a82c4 100644 Binary files a/rss_subscribe/__pycache__/push_article_update.cpython-311.pyc and b/rss_subscribe/__pycache__/push_article_update.cpython-311.pyc differ diff --git a/rss_subscribe/push_article_update.py b/rss_subscribe/push_article_update.py index 0873f0f..e1a1428 100644 --- a/rss_subscribe/push_article_update.py +++ b/rss_subscribe/push_article_update.py @@ -93,4 +93,5 @@ def get_latest_articles_from_link(url, count=5, last_articles_path="./rss_subscr json.dump({'articles': latest_articles}, file, ensure_ascii=False, indent=4) # 如果有更新的文章,返回这些文章,否则返回 None - return updated_articles if updated_articles else None \ No newline at end of file + return updated_articles if updated_articles else None + diff --git a/run.py b/run.py index fab6f12..8a8fa0b 100644 --- a/run.py +++ b/run.py @@ -1,10 +1,14 @@ # 引入 check_feed 和 parse_feed 函数 from friend_circle_lite.get_info import fetch_and_process_data, sort_articles_by_time from friend_circle_lite.get_conf import load_config +from rss_subscribe.push_article_update import get_latest_articles_from_link, extract_emails_from_issues +from push_rss_update.send_email import send_emails + import json +import os # 爬虫部分内容 -config = load_config("./conf.yml") +config = load_config("./conf.yaml") if config["spider_settings"]["enable"]: print("爬虫已启用") json_url = config['spider_settings']['json_url'] @@ -13,4 +17,50 @@ if config["spider_settings"]["enable"]: result = fetch_and_process_data(json_url=json_url, count=article_count) sorted_result = sort_articles_by_time(result) with open("all.json", "w", encoding="utf-8") as f: - json.dump(sorted_result, f, ensure_ascii=False, indent=2) \ No newline at end of file + json.dump(sorted_result, f, ensure_ascii=False, indent=2) + +if config["email_push"]["enable"] or config["rss_subscribe"]["enable"]: + print("获取smtp配置信息") + email_settings = config["smtp"] + email = email_settings["email"] + server = email_settings["server"] + port = email_settings["port"] + use_tls = email_settings["use_tls"] + password = os.environ["SMTP_PWD"] + +if config["email_push"]["enable"]: + print("邮件推送已启用") + +if config["rss_subscribe"]["enable"]: + print("RSS通过issue订阅已启用") + github_username = config["rss_subscribe"]["github_username"] + github_repo = config["rss_subscribe"]["github_repo"] + your_blog_url = config["rss_subscribe"]["your_blog_url"] + github_api_url = "https://api.github.com/repos/" + github_username + "/" + github_repo + "/issues" + "?state=closed" + print("正在从 {github_api_url} 中获取订阅信息".format(github_api_url=github_api_url)) + email_list = extract_emails_from_issues(github_api_url) + if email_list == None: + email_list = {"email": []} + print("获取到的邮箱列表为:", email_list["email"]) + # 获取最近更新的文章 + latest_articles = get_latest_articles_from_link( + url=your_blog_url, + count=5, + last_articles_path="./rss_subscribe/last_articles.json" + ) + print("最新文章为:", latest_articles) + if latest_articles == None: + print("没有新文章") + else: + send_emails( + emails=email_list["email"], + sender_email=email, + smtp_server=server, + port=port, + password=password, + subject="最新文章推送", + body="最新文章为:\n" + "\n".join([article["title"] + " " + article["link"] for article in latest_articles]), + use_tls=use_tls + ) + +