def send_mail(self,title, content):
		'''
		出现异常是发送邮件报告
		'''
		#初始化邮件发送对象

		email = MailSender()
		try:
			email_to = self.config.get('email','receiver')
			email_receivers = email_to.split(';')
			email.sendMail(email_receivers,title, str(content))
		except Exception, ex: 
			return 
class CaculateFeatures4Model():
	def __init__(self, conf_path = '..', feature_num = 18):
		self.feature_num = feature_num
		#other config such as email recivers
		self.filecfg = '%s/conf/main.cfg' % (conf_path)
		self.fileconfig = RawConfigParser()
		self.fileconfig.read(self.filecfg)
		# config email info
		self.mail_recivers = self.setMailReceiver('email', 'receiver')
		self.mail_sender = MailSender()

		self.feature_index = {}
		self.classify_index = {}
		self.weight_index = {}
		self.weight_value = {}
		self.product_info = {}
		self.product_norm_info = {}
		self.setFeatureAndClassifyIndex()

	def setMailReceiver(self,section = 'email', part = 'receiver'):
		email_list = self.fileconfig.get(section,part).split(',')
		mail_receiver = []
		lenght = len(email_list)
		for i in range(lenght):
			email = email_list[i].strip(' ')
			if email == '':
				continue
			mail_receiver.append(email)
		return mail_receiver

	def setFeatureAndClassifyIndex(self, section="index"):
		feature_list = self.fileconfig.get(section,"feature_index").strip().split(',')
		lenght = len(feature_list)
		for i in range(lenght):
			array = feature_list[i].strip().split(':')
			feature_index = int(array[0])
			feature_name = array[1].strip()
			self.feature_index[feature_index] = feature_name

		classify_list = self.fileconfig.get(section,"classify_index").split(',')
		lenght = len(classify_list)
		for i in range(lenght):
			array = classify_list[i].strip().split(':')
			classify_index = int(array[0])
			classify_name = array[1].strip()
			self.classify_index[classify_name] = classify_index

		weight_list = self.fileconfig.get(section,"weight_index").split(',')
		lenght = len(weight_list)
		for i in range(lenght):
			array = weight_list[i].strip().split(':')
			weight_index = int(array[0])
			weight_name = array[1].strip()
			self.weight_index[weight_index] = weight_name

	def initWeights(self, filepath):
		file = None
		try:
			k = 0
			file = open(filepath, 'r')
			while True:
				line = file.readline()
				if not line:
					break
				item_name = self.weight_index[k]
			#	print item_name
				self.weight_value[item_name] = float(line.strip())
				k += 1
		except Exception,ex:
			self.logger.error(ex)
			self.mail_sender.sendMail(self.mail_recivers)
			raise Exception, ex		
		finally:
class ShopInfo(object):
	def __init__(self, conf_path = '..'):
		'''
		init
		'''
		#db redis config file position
		self.conncfg = '%s/conf/connect.cfg' % (conf_path)
		#log config file
		self.logcfg = '%s/conf/logger.conf' % (conf_path)
		logging.config.fileConfig(self.logcfg)
		self.logger = logging.getLogger('log')
		#other config such as email recivers
		self.filecfg = '%s/conf/main.cfg' % (conf_path)
		self.fileconfig = RawConfigParser()
		self.fileconfig.read(self.filecfg)
		#sql config file
		self.sqlcfg = '%s/conf/sql.cfg' % (conf_path)
		self.config = RawConfigParser()
		self.config.read(self.conncfg)
		self.sqlfig = RawConfigParser()
		self.sqlfig.read(self.sqlcfg)
		#connect db redis
		self.conn_shop_db = self.connDbserver('com_shop_review')
		self.sql = self.sqlfig.get('select', 'select_shop_info')	
		# config email info
		self.mail_recivers = self.setMailReceiver('email', 'receiver')
		self.mail_sender = MailSender()

		#dict
		self.shopid_info_score = {}
		self.shopid_price_score = {}
		self.shopid_payment_score = {}
		self.shopid_deliver_score = {}
		self.shopid_package_score = {}
		self.shopid_average_score = {}
		
		#shop average score
		self.shopid_scores = {}
		

	def setMailReceiver(self,section = 'email', part = 'receiver'):
		email_list = self.fileconfig.get(section,part).split(',')
		mail_receiver = []
		lenght = len(email_list)
		for i in range(lenght):
			email = email_list[i].strip(' ')
			if email == '':
				continue
			mail_receiver.append(email)
		return mail_receiver

	def connDbserver(self, section):
		dbserver = None
		try:
			dbtype = self.config.get(section, 'dbtype')
			host = self.config.get(section, 'host')
			port = self.config.get(section, 'port')
			user = self.config.get(section, 'user')
			password = self.config.get(section, 'password')
			database = self.config.get(section, 'database')
			dbserver = DBFactory.Connect(dbtype = dbtype, host = host, database = database, \
					charset = 'utf8',user = user, password = password, port = port)
		except Exception, ex:
			self.logger.error(ex)
			print 'Can not connect to dbserver'
			self.mail_sender.sendMail(self.mail_recivers)
			raise Exception, ex
		return dbserver