from email.mime.text import MIMEText
import feedparser
db_connection = sqlite3.connect('/var/tmp/magazine_rss.sqlite')
db = db_connection.cursor()
db.execute(' CREATE TABLE IF NOT EXISTS magazine (title TEXT, date TEXT)')
这个功能的重要部分是一个 SQL 萌芽,我们运行它去搜刮数据库。我们应用一个 SELECT
敕令去定义我们将要在哪个列上运行这个萌芽。我们应用 *
符号去拔取所有列(title
和 date
)。然后,我们应用萌芽的 WHERE
前提 article_title
和 article_date
去匹配标题和日期列中的值,以检索出我们须要的内容。
最后,我们应用一个简单的返回 True
或者 False
的逻辑来表示是否在数据库中找到匹配的文┞仿。
在数据库中添加新文┞仿
如今我们可以写一些代码去添加新文┞仿到数据库中。
这个功能很简单,我们应用了一个 SQL 萌芽去插入一个新行到 magazine
表的 article_title
和 article_date
列中。然后提交它到数据库中永远保存。
def add_article_to_db(article_title, article_date):
""" Add a new article title and date to the database
Args:
article_title (str): The title of an article
article_date (str): The publication date of an article
"""
db.execute("INSERT INTO magazine VALUES (?,?)", (article_title, article_date))
db_connection.commit()
这些就是在数据库中所须要的器械,接下来我们看一下,若何应用 Python 实现提示体系和发送电子邮件。
发送电子邮件提示
我们应用 Python 标准库模块 smtplib 来创建一个发送电子邮件的功能。我们也可以应用标准库中的 email 模块去格局化我们的电子邮件信息。
def send_notification(article_title, article_url):
""" Add a new article title and date to the database
Args:
article_title (str): The title of an article
article_url (str): The url to access the article
"""
smtp_server = smtplib
推荐阅读
全平易近充电节 | 3月26日~30日 2000位IT行业拭魅战专家邀请你一路充电进修! 就在前天,Facebook爆发了史上最大年夜的数据危机:其开放API接口给第三方公司,在未经用户许可的情况下,被盗>>>详细阅读
本文标题:用Python构建你自己的RSS提示系统
地址:http://www.17bianji.com/lsqh/40816.html
1/2 1