Exemplo n.º 1
0
 def __init__(self,
              folder=[],
              creator=MySQLdb,
              maxusage=None,
              setsession=None,
              failures=None,
              ping=1,
              closeable=False,
              threadlocal=local,
              *args,
              **kwargs):
     """
     :param folder: xml映射文件所在的文件夹
     :param creator: 创建新的DB API 2连接的函数或DB API 2数据库适配器模块
     :param maxusage: 单个连接重复使用次数
     :param setsession: 初始化数据库会话的SQL命令参数,形式list
     :param failures: 故障转移的可选异常类或异常类元组
     :param ping: 使用ping()检查连接的时间,0从不检查,默认1请求时检查,2创建游标检查,4执行检查之前检查,7所有情况
     :param closeable: 为 True 时,允许自行关闭链接
     :param threadlocal:
     args, kwargs: 传递给 creator 的构造函数/初始化方法的参数
     """
     self.folder = folder
     self.pool = PersistentDB(creator=creator,
                              maxusage=maxusage,
                              setsession=setsession,
                              failures=failures,
                              ping=ping,
                              closeable=closeable,
                              threadlocal=threadlocal,
                              *args,
                              **kwargs)
     # 定义允许的操作类型
     self.crud = ['select', 'insert', 'update', 'delete']
Exemplo n.º 2
0
class MySQLPool(object):
    __metaclass__ = MetaSingleton

    def __init__(self, pool_size, **kwargs):
        self._pool_size = pool_size
        self._pooled = PersistentDB(pymysql, pool_size, **kwargs)

    def get_db(self):
        return self._pooled.connection()

    def pool_size(self):
        return self._pool_size
Exemplo n.º 3
0
class MySQLPool(object):
    __metaclass__ = MetaSingleton

    def __init__(self, pool_size, **kwargs):
        self._pool_size = pool_size
        self._pooled = PersistentDB(pymysql, pool_size, **kwargs)

    def get_db(self):
        return self._pooled.connection()

    def pool_size(self):
        return self._pool_size
Exemplo n.º 4
0
def init_connection_pool(conf):
    global pool_holder
    if pool_holder.pool is not None:
        # raise Exception("Trying to initialize mysql connection pool twice")
        return # Silently success
    try:
        pool_holder.pool = PersistentDB.PersistentDB(MySQLdb, 1000,
                                         host=conf['MYSQL']['host'],
                                         port=conf['MYSQL']['port'],
                                         user=conf['MYSQL']['username'],
                                         passwd=conf['MYSQL']['password'],
                                         db=conf['MYSQL']['dbname'],
                                         charset='utf8',
                                         setsession=['set autocommit = 1'])
    except Exception, e:
        log.error("failed to initialize mysql connection pool, message : %s" % (e.message))
        log.error(traceback.format_exc())
Exemplo n.º 5
0
import logging
from email import utils
import traceback
from sklearn.externals import joblib
import base64
from email.header import decode_header
import MySQLdb
sys.setdefaultencoding('utf8')

stop_words = ['面试', '邀请', '介绍', '加入', '公司', '有限', '机会', '职位', '推荐', '简介', '月薪', '工作',\
              '服务', '开发', '北京', '高级', '回复', '邀请函', '并', '查收', '工程师', '】', '来信', '您',\
              '请', '收到', '谢谢', '通知', '网络', '沟通', '邮件', '诚邀', '来自', '北京', '-', '技术',\
              '核心', '关于', '的', '—', '候选人', '有限公司', '软件', '(', '上海', '【', '资深', 'PHP',\
              '来自', ':', '招聘', '上市', '互联网', '金融', '感谢', '欢迎', '关注']

persist = PersistentDB.PersistentDB(MySQLdb, host='121.40.183.7', port=3306, user='******',\
                                    passwd='8e1c7d52557b', db='reply_analyze', charset='utf8')

comma_tokenizer = lambda x: jieba.cut(x, cut_all=True)
clf = joblib.load('mailclassify/clf.model')


def vectorize(test_words):
    v = HashingVectorizer(tokenizer=comma_tokenizer,
                          n_features=30000,
                          non_negative=True)
    test_data = v.fit_transform(test_words)
    return test_data


def predict_mail(subject):
    # pdb.set_trace()
Exemplo n.º 6
0
#coding:utf8
import sys
from DBUtils import PersistentDB
reload(sys)
import MySQLdb

sys.setdefaultencoding = 'utf8'


persist = PersistentDB.PersistentDB(MySQLdb, host='127.0.0.1', port=3306, user='******',\
                                    passwd='123456', db='naren', charset='utf8')
Exemplo n.º 7
0
 def __init__(self, pool_size, **kwargs):
     self._pool_size = pool_size
     self._pooled = PersistentDB(pymysql, pool_size, **kwargs)
Exemplo n.º 8
0
 def __init__(self, pool_size, **kwargs):
     self._pool_size = pool_size
     self._pooled = PersistentDB(pymysql, pool_size, **kwargs)
Exemplo n.º 9
0
import MySQLdb

sys.setdefaultencoding = 'utf8'

import ConfigParser

cf = ConfigParser.ConfigParser()

cf.read('database.ini')
host = cf.get('database', 'host')
port = cf.get('database', 'port')
user = cf.get('database', 'user')
db = cf.get('database', 'db')
passwd = cf.get('database', 'passwd')

persist = PersistentDB.PersistentDB(MySQLdb, host=host, port=int(port), user=user,\
                                    passwd=passwd, db=db, charset='utf8')

# persist = PersistentDB.PersistentDB(MySQLdb, host='127.0.0.1', port=3306, user='******',\
#                                     passwd='123456', db='fkmodelt', charset='utf8')

# persist = PersistentDB.PersistentDB(MySQLdb, host='121.40.183.7', port=3306, user='******',\
#                                     passwd='8e1c7d52557b', db='fkmodel', charset='utf8')

digitlst = [
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
    'f'
]


def discrement_unicode(stw):
    strs = stw.replace('u', '\u')