The following code used to work using an SQLite file, but now that I've converted the db…
- User
The following code used to work using an SQLite file, but now that I've converted the db into a Postgres db, it doesn't work anymore. There are two types employed in the new db (text and bigint) compared to the old db (text and number). The voll column (text) contains a JSON string.
import requests,json,re,sqlite3,gc,os,sys,time,unicodedata,traceback,html,random
from lxml.html import fromstring from flask import Flask,request,session,send_from_directory,render_template,send_file,redirect from threading import Thread,Event,local from datetime import datetime import psycopg2 import psycopg2.extras
import grab_server,grab_search,grab_watch,settings,imagesize
s = requests.Session() ''' connection=sqlite3.connect(settings.filename, check_same_thread=False) connection.execute('PRAGMA journal_mode=WAL;') connection.text_factory = sqlite3.Binary cursor=connection.cursor() '''
Connection parameters
conn_params = { 'dbname': 'blabla', 'user': 'bla', 'host': 'localhost', # or the address of your PostgreSQL server 'port': '5432' # default PostgreSQL port }
Connect to PostgreSQL
connection = psycopg2.connect(**conn_params)
Create a cursor
cursor = connection.cursor()
Enable autocommit if needed (optional)
connection.autocommit = True
Use psycopg2's Binary for binary data
psycopg2_extras = psycopg2.extras
_thread_locals = local()
app = Flask(name) app.config['SECRET_KEY']='ENTERSOMETHINGRANDOM'
app.template_folder = "."
app.url_map.strict_slashes = False
page=1
def setup_fts(): # Create the FTS table cursor.execute(''' CREATE VIRTUAL TABLE IF NOT EXISTS messages_fts USING fts5( id1 UNINDEXED, id2 UNINDEXED, board UNINDEXED, message, subject, files, date, tokenize = 'unicode61' ); ''') connection.commit()
code - Assistant