Skip to content

Commit

Permalink
misc bugfixes, mostly mysql-related
Browse files Browse the repository at this point in the history
  • Loading branch information
fhocutt committed Jan 30, 2015
1 parent dd0402e commit e278f7e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions matchbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ def gettimeposted(result, isflow):

for learner in learners:
try:
mcat = mcat_dict[learner['category']]
mentor = match(mentors[mcat], genmentors)
mentorcat = mentorcat_dict[learner['category']]
mentor = match(mentors[mentorcat], genmentors)
except Exception as e:
mblog.logerror('Matching failed for {}'.format(learner['learner']),
exc_info=True)
Expand Down Expand Up @@ -302,7 +302,7 @@ def gettimeposted(result, isflow):

try:
response = postinvite(talkpage, greeting, topic, flowenabled,
learner)
learner['learner'])
edited_pages = True
except Exception as e:
mblog.logerror('Could not post match on {}\'s page'.format(
Expand All @@ -314,11 +314,11 @@ def gettimeposted(result, isflow):
revid, postid = getrevid(response, flowenabled)
matchtime = gettimeposted(response, flowenabled)
cataddtime = parse_timestamp(learner['cattime'])
mblog.logmatch(luid=learner['luid'], lprofile=learner['profile'],
"""mblog.logmatch(luid=learner['luid'], lprofile=learner['profile'],
muid=muid, category=skill, cataddtime=cataddtime,
matchtime=matchtime, matchmade=matchmade,
revid=revid, postid=postid, run_time=run_time)
mblog.logmatchmysql(luid=learner['luid'], lprofile=learner['profile'],
revid=revid, postid=postid, run_time=run_time)"""
mblog.logmatchmysql(luid=learner['luid'], lprofileid=learner['profileid'],
muid=muid, category=skill, cataddtime=cataddtime,
matchtime=matchtime, matchmade=matchmade,
revid=revid, postid=postid, run_time=run_time)
Expand Down
10 changes: 5 additions & 5 deletions mblog.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def logerror(message, exc_info=False):
# TODO: get running on labs
# TODO: take echo=True out for production
# TODO: check whether post-revision-id is a string or int
def logmatch(luid, lprofile, category, muid, matchtime,
def logmatch(luid, lprofileid, category, muid, matchtime,
cataddtime, matchmade, run_time, revid=None, postid=None):
"""Log information about the match to a relational database.
Expand All @@ -94,7 +94,7 @@ def logmatch(luid, lprofile, category, muid, matchtime,
autoload_with=engine)
ins = matches.insert()
conn = engine.connect()
conn.execute(ins, {'luid': luid, 'lprofile': lprofile,
conn.execute(ins, {'luid': luid, 'lprofileid': lprofileid,
'category': category, 'muid': muid,
'matchtime':matchtime, 'cataddtime': cataddtime,
'revid': revid, 'postid': postid,
Expand All @@ -106,10 +106,10 @@ def makeconnstr():
password = config['dbinfo']['password']
host = config['dbinfo']['host']
dbname = config['dbinfo']['dbname']
conn_str = 'mysql://{}:{}@{}/{}'.format(username, password, host, dbname)
conn_str = 'mysql://{}:{}@{}/{}?charset=utf8&use_unicode=0'.format(username, password, host, dbname)
return conn_str

def logmatchmysql(luid, lprofile, category, muid, matchtime,
def logmatchmysql(luid, lprofileid, category, muid, matchtime,
cataddtime, matchmade, run_time, revid=None, postid=None):
"""Same as logmatch, but uses a MySQL database backend."""
conn_str = makeconnstr()
Expand All @@ -119,7 +119,7 @@ def logmatchmysql(luid, lprofile, category, muid, matchtime,
autoload_with=engine)
ins = matches.insert()
conn = engine.connect()
conn.execute(ins, {'luid': luid, 'lprofile': lprofile,
conn.execute(ins, {'luid': luid, 'lprofileid': lprofileid,
'category': category, 'muid': muid,
'matchtime':matchtime, 'cataddtime': cataddtime,
'revid': revid, 'postid': postid, 'matchmade':
Expand Down
8 changes: 4 additions & 4 deletions misc/sqlcreateinsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ def createtable(conn_str):
matches = sqa.Table('matches', metadata,
sqa.Column('id', sqa.Integer, primary_key = True),
sqa.Column('luid', sqa.Integer),
sqa.Column('lprofile', sqa.Integer),
sqa.Column('lprofileid', sqa.Integer),
sqa.Column('category', sqa.String(75)),
sqa.Column('muid', sqa.Integer),
sqa.Column('matchtime', sqa.DateTime),
sqa.Column('cataddtime', sqa.DateTime),
sqa.Column('revid', sqa.Integer),
sqa.Column('postid', sqa.Integer),
sqa.Column('postid', sqa.String(50)),
sqa.Column('matchmade', sqa.Boolean),
sqa.Column('run_time', sqa.DateTime))
metadata.create_all(engine)

def insertmatches(conn_str, luid, lprofile, category, muid, matchtime,
def insertmatches(conn_str, luid, lprofileid, category, muid, matchtime,
cataddtime, matchmade, run_time, revid=None, postid=None):
engine = sqa.create_engine(conn_str, echo=True)
metadata = sqa.MetaData()
matches = sqa.Table('matches', metadata, autoload=True,
autoload_with=engine)
ins = matches.insert()
conn = engine.connect()
conn.execute(ins, {'luid': luid, 'lprofile': lprofile,
conn.execute(ins, {'luid': luid, 'lprofileid': lprofileid,
'category': category, 'muid': muid,
'matchtime':matchtime, 'cataddtime': cataddtime,
'revid': revid, 'postid': postid, 'matchmade':
Expand Down

0 comments on commit e278f7e

Please sign in to comment.