def create_profile(self, logger, msisdn): assert type(msisdn) in (int, long, str, list) """phonelist = [] if(type(msisdn) in (int, long, str)): phonelist = [str(msisdn)] else: phonelist = list """ #prepare sql statement db = DBCon().get_connection(logger) conf = UVConf(); l_lang = conf.get("core", "lang") l_telcoid = conf.get("core", "telcoid") l_query = "INSERT INTO tbl_user_profile(msisdn, user_name, display_name, channel, created_ts, operator_id, lang, privacy) VALUES ('%s','%s','%s',21, now(), '%s', '%s', 'public')"%(msisdn, msisdn, msisdn, l_lang, l_telcoid) #l_valuepart = '' #for phnum in phonelist: # l_valuepart = l_valuepart + "('%s','%s','%s',now(), '%s', '%s', 'public')"%(phnum, phnum, phnum, l_lang, l_telcoid) #l_query = l_query + l_valuepart logger.debug("user profile creation query = %s", l_query) try: cursor = db.cursor() cursor.execute(l_query) except: logger.critical("Failed to run query %s. Terminating now", l_query) logger.exception(traceback.print_exc()) sys.exit(1)
def get_connection(self, logger): conf = UVConf(); l_host = conf.get("db","coredb_host") l_user = conf.get("db","coredb_user") l_passwd = conf.get("db","coredb_passwd") l_db = conf.get("db","coredb_name") logger.info("Mysql Connection setup params - host = %s, user = %s, passwd = %s, db = %s", l_host, l_user, l_passwd, l_db) try: self.db = MySQLdb.connect(host=l_host, user=l_user, passwd=l_passwd, db=l_db) logger.info("connected to database. %s", str(self.db)) except: logger.critical("Failed to connect to database. Terminating now. Traceback ...") logger.exception(traceback.print_exc()) sys.exit(1) return self.db