#! /usr/bin/python
# -*- coding: utf-8 -*-


import MySQLdb, xlrd, sys
from GpConfig import GpConfig

config = GpConfig()

conn = MySQLdb.connect(host=config.host,user=config.user,
                        passwd=config.pw,db=config.db,port=config.port,charset='utf8')

######################add table => excel###########
addt2x = {}
addt2x['OrgiID']='FileName'

##########
addt2p = {}
addt2p['GaopinID'] = 'gaopinId'
addt2p['StorageID'] = 'storageId'
addt2p['Width']='width'
addt2p['Height']='height'
#addt2p['MaxSizeCode']='sizeCode'
addt2p['PhotographerId']='photographerId'
addt2p['motionColor']='motionColor'
addt2p['OriginalFilename']='FileName'
addt2p['SourceImagePath']='filePathName'
addt2p['ModelReleaseRequired']='modelReleaseRequired'
addt2p['PropertyReleaseRequired']='propertyReleaseRequired'
addt2p['orgi_MediaRatingText']='orgiMediaRatingText'
#addt2p['LeftShotDate'] = 'leftShotDate'
#addt2p['RightShotDate'] = 'rightShotDate'
addt2p['ModelIdentification'] = 'ModelIdentification'
addt2p['SourcePreFlvPath'] = 'SourcePreFlvPath'
addt2p['SourcePreMp4Path'] = 'SourcePreMp4Path'
addt2p['SourceDetMp4Path'] = 'SourceDetMp4Path'
addt2p['SourcePreWebmPath'] = 'SourcePreWebmPath'
addt2p['SourceDetWebmPath'] = 'SourceDetWebmPath'

addt2d = {}
#addt2d['Status'] = '0'
#addt2d['Remark'] = config.remark
addt2d['CreatedAt'] = '@d'
addt2d['SelectedDate'] = '@d'

###################################################

tableName = sys.argv[2]
#print tableName

cur = conn.cursor()
sql = 'desc %s' % tableName

cur.execute(sql)

tColName={}
for row in cur:
	tColName[row[0]]=row[1][0:1]

xls = xlrd.open_workbook(sys.argv[1])
table = xls.sheets()[0]
xColName = table.row_values(0)
sqlColName={}
for tcn in tColName.keys():
	sqlColName[tcn] = 'n:'+tColName[tcn]+':'
	sMark = True
	for xcn in xColName:
		if tcn.lower() == xcn.lower():
			sqlColName[tcn] = 'x:'+tColName[tcn]+':'+xcn
			sMark = False
			break
	if sMark:
		if tcn in addt2x:
			sqlColName[tcn] = 'x:'+tColName[tcn]+':'+addt2x[tcn]
		elif tcn in addt2p:
			sqlColName[tcn] = 'p:'+tColName[tcn]+':'+addt2p[tcn]
		elif tcn in addt2d:
			sqlColName[tcn] = 'd:'+tColName[tcn]+':'+addt2d[tcn]

for cn in sqlColName.keys():
	print cn+'='+sqlColName[cn]

