Commit 03a7caa5 authored by Brett Wilkins's avatar Brett Wilkins Committed by Jonathan Harker

Fix UTF8 database issue.

parent 6e9a61b3
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
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment