Example #1
0
  def load_rules_from_db(self, *args):
    logger = None
    try:
      logger = args[0]
    except:
      sys.stderr.write("Expecting logger into first explicit argument in NumNormalizer::load_rules_from_db. Parameter is missing or not valid. Terminating")
      sys.stderr.write(traceback.print_exc())
      sys.stderr.flush()
      sys.exit(1)

    db = DBCon().get_connection(logger)
    l_query = "SELECT id, in_pattern, out_pattern, telco_id, channel, description FROM tbl_number_normalizer ORDER BY id DESC"
    numrows = 0
    try:
      cursor = db.cursor()
      cursor.execute(l_query)
      numrows = int(cursor.rowcount)
      if numrows == 0:
        logger.critical("No rows found [%d] in tbl_number_normalizer. Terminating application now ", numrows)
        sys.exit(1)
      else:
        logger.info("[%d] rows found in tbl_number_normalizer. loading now ", numrows)
    except:
      logger.critical("Failed to run query %s. Terminating now", l_query)
      logger.exception(traceback.print_exc())
      sys.exit(1)
        
    for iter in range(0,numrows):
      row = cursor.fetchone()
      logger.info("id = %d, in_pattern = %s, out_pattern = %s, telco_id = %s, channel = %s, description = %s ", int(row[0]), row[1], row[2], row[3], row[4], row[5])
      self.normalize_rules.append(row)
    logger.info("%d normalized rules loaded successfully", numrows)
Example #2
0
  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)