drime

French rhyme dictionary with web and CLI interface
git clone https://a3nm.net/git/drime/
Log | Files | Refs | README

db_mysql.py (425B)


      1 #!/usr/bin/env python3
      2 
      3 import pymysql
      4 import pymysql.cursors
      5 from db_mysql_config import config
      6 
      7 def run_query(r, v):
      8   db = pymysql.connect(
      9       host=config['host'],
     10       user=config['user'],
     11       passwd=config['passwd'],
     12       db=config['db'],
     13       cursorclass=pymysql.cursors.DictCursor,
     14       charset='utf8',
     15       use_unicode=True)
     16   cursor = db.cursor()
     17   cursor.execute(r.replace('?', '%s'), v)
     18   return cursor
     19