python中文昵称-python实例pyspark以及python中文显示

%pyspark#查询认证用户import sys#import MySQLdbimport mysql.connectorimport pandas as pdimport datetimeimport timeoptmap = {'dbuser' : 'haoren','dbpass' : 'G4d','dbhost' : '172.12.112.5','dbport' : 3306,'dbname' : 'GMDB'}def sql_select(reqsql):ret = ''try:db_conn = mysql.connector.connect(user=optmap['dbuser'], password=optmap['dbpass'], host=optmap['dbhost'], port=optmap['dbport'], database=optmap['dbname'])db_cursor=db_conn.cursor()count = db_cursor.execute(reqsql)ret = db_cursor.fetchall()except mysql.connector.Error as e:print ('Error : {}'.format(e))finally:db_cursor.close()db_conn.closereturn retuserlist = []def renzhengsingger(startday,endday):t1 = int(time.mktime(time.strptime(startday,'%Y-%m-%d %H:%M:%S')) )t2 = int(time.mktime(time.strptime(endday,'%Y-%m-%d %H:%M:%S')))for n in range(0,10):reqsql = "select PERFORMERID,sum(DURATION)/3600 from PERFORMERSHOWTIMERECORD%d where STARTTIME >=%s and STARTTIME <%s group by PERFORMERID ;" %(n,t1,t2)ret = sql_select(reqsql)userlist.append(ret)#print userlistfor i in range(0,10):for p in userlist[i]:print p[0],p[1]renzhengsingger('2017-08-01 00:00:00','2017-09-01 00:00:00')======================================================================================================================%pyspark#查询认证用户import sys#import MySQLdbimport mysql.connectorimport pandas as pdimport datetimeimport timeoptmap = {'dbuser' : 'haoren','dbpass' : 'G4d','dbhost' : '172.12.112.8','dbport' : 3306,'dbname' : 'IMDB'}optmap1 = {'dbuser' : 'haoren','dbpass' : 'G4d','dbhost' : '172.12.112.5','dbport' : 3306,'dbname' : 'GMDB'}def sql_select(reqsql):ret = ''try:db_conn = mysql.connector.connect(user=optmap['dbuser'], password=optmap['dbpass'], host=optmap['dbhost'], port=optmap['dbport'], database=optmap['dbname'])db_cursor=db_conn.cursor()count = db_cursor.execute(reqsql)ret = db_cursor.fetchall()except mysql.connector.Error as e:print ('Error : {}'.format(e))finally:db_cursor.close()db_conn.closereturn retdef sql_select1(reqsql1):ret = ''try:db_conn1 = mysql.connector.connect(user=optmap1['dbuser'], password=optmap1['dbpass'], host=optmap1['dbhost'], port=optmap1['dbport'], database=optmap1['dbname'])db_cursor1=db_conn1.cursor()count = db_cursor1.execute(reqsql1)ret1 = db_cursor1.fetchall()except mysql.connector.Error as e:print ('Error : {}'.format(e))finally:db_cursor1.close()db_conn1.closereturn ret1#定义查询认证用户函数def renzhengsingger(startday,endday):t1 = int(time.mktime(time.strptime(startday,'%Y-%m-%d %H:%M:%S')) )t2 = int(time.mktime(time.strptime(endday,'%Y-%m-%d %H:%M:%S')))reqsql = "select PERFORMERID,from_unixtime(ADDTIME) from PERFORMERINFO where ADDTIME >=%s and ADDTIME < %s" %(t1,t2)ret = sql_select(reqsql)for i in ret:#print i[0]id = int(i[0])%10reqsql1 = "select sum(DURATION)/3600 from PERFORMERSHOWTIMERECORD%d where STARTTIME >=%s and STARTTIME <%s and PERFORMERID=%d" %(id,t1,t2,i[0])#print reqsql1ret1 = sql_select1(reqsql1)print i[0],",",i[1],",",ret1[0][0]renzhengsingger('2017-08-01 00:00:00','2017-09-01 00:00:00')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值