Fix UTF8 database issue.
This commit is contained in:
parent
6e9a61b3bf
commit
03a7caa548
2 changed files with 10 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
irc.server = irc.freenode.net
|
||||
irc.channel = #lolbottest
|
||||
|
||||
# db.url can be any URL that works with SQLAlchemy
|
||||
db.url = sqlite:///lolbot.db
|
||||
# sqlite database filename
|
||||
db.url = lolbot.db
|
||||
|
||||
|
|
|
|||
10
lolbot.py
Executable file → Normal file
10
lolbot.py
Executable file → Normal file
|
|
@ -16,12 +16,13 @@ try:
|
|||
import random
|
||||
import time
|
||||
import getopt
|
||||
import sqlite3
|
||||
from twisted.words.protocols import irc
|
||||
from twisted.internet import protocol
|
||||
from twisted.internet import reactor
|
||||
from datetime import datetime
|
||||
from mechanize import Browser
|
||||
from sqlalchemy import MetaData, Table, Column, String, Text, Integer, DateTime, engine_from_config
|
||||
from sqlalchemy import MetaData, Table, Column, String, Text, Integer, DateTime, create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
except ImportError:
|
||||
|
|
@ -116,9 +117,14 @@ class LolBot(irc.IRCClient):
|
|||
The Lolbot itself.
|
||||
"""
|
||||
|
||||
def _get_connection(self):
|
||||
connection = sqlite3.Connection(self.config['db.file'])
|
||||
connection.text_factory = str
|
||||
return connection
|
||||
|
||||
def created(self, when):
|
||||
# connect to the database
|
||||
self.dbengine = engine_from_config(self.config, prefix="db.")
|
||||
self.dbengine = create_engine('sqlite+pysqlite://', creator=self._get_connection)
|
||||
SqlBase.metadata.bind = self.dbengine
|
||||
SqlBase.metadata.create_all()
|
||||
self.get_session = sessionmaker(bind=self.dbengine)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue