python批量转换数据库markdown为html

该程序是使用Python把sqlite的article表中的content字段全部由markdown转换为html。 首先安装依赖:

pip install sqlite3
pipinstall markdown

以下是程序主体:

import sqlite3
import markdown
conn = sqlite3.connect('test.db')
cursor = conn.cursor()
for i in range(0,900):
    try:
        a = cursor.execute('select content from articles where id = %s'%i).fetchall()
        for a1 in a:
            cursor.execute("update articles set content = '%s' where id = '%s'"%(markdown.markdown(a1[0]),i))
            conn.commit()
    except:
        continue

经测试python2和python3都可以正常运行。

本文为原创文章,转载请注明出处。

原文链接:https://850406.xyz/post/python批量转换数据库markdown为html

评论(0)

还没有评论,来抢沙发吧~

验证码