本文整理汇总了Python中link.Link.connectMysql方法的典型用法代码示例。如果您正苦于以下问题:Python Link.connectMysql方法的具体用法?Python Link.connectMysql怎么用?Python Link.connectMysql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类link.Link
的用法示例。
在下文中一共展示了Link.connectMysql方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestLinkMethods
# 需要导入模块: from link import Link [as 别名]
# 或者: from link.Link import connectMysql [as 别名]
class TestLinkMethods(unittest.TestCase):
def setUp(self):
self.c = Link()
pass
def tearDown(self):
pass
def test_connectMysql(self):
db = self.c.connectMysql(db = 'maimai')
db.query('show tables')
rows = db.fetchAllRows()
self.assertEqual(type(rows), tuple)
def test_connectRedis(self):
redis = self.c.connectRedis()
keys = redis.keys()
self.assertEqual(type(keys), list)
def test_connectSphinx(self):
sphinx = self.c.connectSphinx()
res = sphinx.query('a')
self.assertIn('status', res)
self.assertIn('matches', res)
示例2: Model
# 需要导入模块: from link import Link [as 别名]
# 或者: from link.Link import connectMysql [as 别名]
class Model(object):
"""docstring for Model"""
db = None # mysql
r = None # redis
sp = None # sphinx
# 教育信息对应关系
eduDegreeMap = {
'0': '专科',
'1': '本科',
'2': '硕士',
'3': '博士',
'4': '博士后',
'5': '中学',
'255': '其他',
}
def __init__(self):
self.tool = Tool()
self.link = Link()
if not self.db:
self.db = self.link.connectMysql(db = 'maimai')
if not self.r:
self.r = self.link.connectRedis()
if not self.sp:
self.sp = self.link.connectSphinx()
cf = ConfigParser()
cf.read('conf/config.ini')
self.imageHost = cf.get('aliyun_oss', 'host')
def getImageUrlFromOSS(self, keyword, imgType = 'user'):
"""从OSS获取图片地址
Args:
keyword string 关键词, 分别对应类型为(user[id], company[pycompany], school[pyschool])
imgType string 类型:user/company/school
Returns:
The image url saved OSS.
"""
if imgType == 'user':
intId = keyword
url = '/avatar/' + self.tool.md5(u'm_d_' + str(intId)) + '.jpeg'
elif imgType == 'company':
pass
elif imgType == 'school':
pass
else:
return ''
return self.imageHost + url
""" 用户信息 start"""
def getUser(self, intId):
"""
查询用户信息,工作经历,教育经历
Args:
intId - 用户主键id
Returns:
user info dict.
{
'user': [],
'works': [],
'edus': [],
}
"""
sql = "select id, uid, name, company_id, company_name, position, avatar, gender, rank, loc, trade, trade_category, create_time from user where id = '%s' " % (intId)
self.db.query(sql)
userInfo = self.db.fetchOneRow()
user = {
'id': userInfo[0],
'uid': userInfo[1],
'name': userInfo[2],
'company_id': userInfo[3],
'company_name': userInfo[4],
'position': userInfo[5],
# 'avatar': userInfo[6],
'avatar': self.getImageUrlFromOSS(userInfo[0], 'user'),
'gender': userInfo[7],
'rank': userInfo[8],
'loc': userInfo[9],
'trade': userInfo[10],
'trade_category': userInfo[11],
'create_time': str(userInfo[12]),
}
uid = user['uid']
# 工作经历
#.........这里部分代码省略.........