jeudi 10 mars 2016

Modify a table of sqlite database using python

I have a sqlite database, let's say test.db. It is the database of my blog, where all the blog contents are stored. Now, it has a table called "posts". "posts" contains all the contents that I have written in my blog. There is a javascript which is present multiple times in the "posts", that I want to replace with something else. So, the concept is to fetch table "posts" and then use regex to select all the similar and then replace it with new one. I fetched the data from "posts" by using a python script. I want help to select using regex and then replace. Below is my code :-

import sqlite3
conn = sqlite3.connect('/home/bootx/Downloads/test.db')
cur = conn.cursor()

def get_posts():
    cur.execute("SELECT * FROM posts")
    print(cur.fetchall())

get_posts()
conn.commit()
conn.close()
print "Connected fetched"

Aucun commentaire:

Enregistrer un commentaire