def insert_or_update_template(self, table, db_dict, unique_key, primary_name='id'):
        select_sql = str()
        for key in unique_key:
            select_sql += key + ' = "' + str(db_dict[key]) + '" and '
        primary_key_id = 0
        if select_sql:
            select_sql = 'select id from %s where %s' % (table, select_sql[:-5])
            data = self.db.get_data(select_sql)
            if data:
                primary_key_id = data[0][primary_name]
        if primary_key_id > 0:
            gmt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            db_dict['gmt_modified'] = gmt
            value_list = list()
            for key, value in db_dict.items():
                value_list.append('%s = "%s"' % (key, str(value)))
            self.db.exec_data('update %s set %s %s' % (
                table, ','.join(value_list), ' where %s = %d' % (primary_name, primary_key_id)))
        else:
            primary_key_id = self.insert_temple(table, db_dict)
        return primary_key_id
dataset/ETHPy150Open wcong/ants/antsext/CrawlDao.py/CrawlDao.insert_or_update_template/original