Example #1
0
def write_log(s_entry="\n",
              s_path="log/",
              s_file="Python_log_" +
              datetime.datetime.now().strftime("%Y%m%d") + ".txt"):
    """
    Function to create log file
    :param s_entry: Log file entry
    :param s_path: Log file path
    :param s_file: Log file name
    :return: Nothing
    """

    # IMPORT OWN MODULES
    from _my_modules import func_configure
    from _my_modules import func_system

    # DECLARE VARIABLES
    l_success: bool = False
    s_project: str = "WRITE_LOG: " + s_file

    try:

        with open(s_path + s_file, 'a', encoding="utf-8") as fl:
            # file opened for writing. write to it here
            # Write the log
            if s_entry == "Now":
                fl.write("----------------\n")
                s_entry = datetime.datetime.now().strftime(
                    "%Y-%m-%d %H:%M") + "\n"
            elif "%t" in s_entry:
                s_entry = s_entry.replace(
                    "%t",
                    datetime.datetime.now().strftime("%H:%M:%S"))
                s_entry += "\n"
            else:
                s_entry += "\n"
            fl.write(s_entry)
            fl.close()
            pass
            l_success = True

    except Exception as err:

        func_system.error_message(
            err, func_configure.s_name_project + ':Fail:' + s_project,
            func_configure.s_name_project + ': Fail: ' + s_project)

    return l_success
Example #2
0
    s_sql: str = "UPDATE `" + s_table + \
                 "` SET `show_in_list_summary` = " + str(i_value) + \
                 " WHERE `name` = '" + s_name + "';"
    # print(s_sql)
    mysql_cur.execute('START TRANSACTION;')
    mysql_cur.execute(s_sql)
    mysql_cur.execute('COMMIT;')
    mysql_cur.close()

    # UPDATE THE LOG
    b_return = True
    if func_configure.l_debug_project:
        print('Updated: Fabrik show-in-list ' + s_name + ' to ' + str(i_value))
    if func_configure.l_log_project:
        func_file.write_log(
            '%t UPDATE SHOW-IN-LIST: ' + s_name + ' to ' + str(i_value),
            func_configure.s_path_project + 'log/')

    return b_return


if __name__ == '__main__':
    try:
        from _my_modules import func_mysql
        sql_cxn = func_mysql.mysql_open(False,
                                        func_configure.s_joomla_database)
        s_tab = func_mysql.get_fabrik_table(False, 'element')
        update_show_in_list(sql_cxn, s_tab, 'ia_findlike_auto', 0)
    except Exception as e:
        func_system.error_message(e)