Beispiel #1
0
def init_mylogger():

    my_logger_name = get_config('logging')['file']

    my_logger = logging.getLogger(my_logger_name)

    if not my_logger.hasHandlers():

        level = get_config('logging')['level']

        my_logger.setLevel(level)

        logger_file_handler = logging.FileHandler(get_config('logging')['file'])

        logger_file_handler.setLevel(level)

        logger_console_handler = logging.StreamHandler()
        logger_console_handler.setLevel(level)

        logger_formatter = logging.Formatter(get_config('logging')['format'])
        logger_console_handler.setFormatter(logger_formatter)
        logger_file_handler.setFormatter(logger_formatter)

        my_logger.addHandler(logger_console_handler)
        my_logger.addHandler(logger_file_handler)

    return my_logger
def init_nav():
    init_globals()
    config = configurator.get_config('blue')
    path = parse_path(config)
    pub_obj_thrtl, pub_obj_steer, pub_obj_brake = init_ros(config)
    try:
        os.remove(
            "/home/oks/catkin_ws/src/framework_sim/gen_txtfiles/controller_output.txt"
        )
        os.remove(
            "/home/oks/catkin_ws/src/framework_sim/gen_txtfiles/cont_fb_out.txt"
        )
    except:
        pass
    return config, path, pub_obj_thrtl, pub_obj_steer, pub_obj_brake
Beispiel #3
0
    def create(self):
        cfgFile = configurator.get_config("general")
        cfg = yaml.load(cfgFile)
        cfgFile.close()

        conn = api()
        conn.url = '/scans'
        conn.data = '{ \"uuid\": \"' + cfg['nessus'][
            'scan_template_uuid'] + '\", \"settings\": { \"name\": \"' + str(
                self.name) + '\", \"enabled\": true, \"folder_id\": ' + str(
                    self.folderID
                ) + ', \"scanner_id\": 1, \"policy_id\": ' + cfg['nessus'][
                    'scan_policy_id'] + ', \"text_targets\": \"' + str(
                        self.target) + '\" }}'
        self.ID = conn.sendRequest()["scan"]["id"]
Beispiel #4
0
    def sendRequest(self):
        cfgFile = configurator.get_config("general")
        cfg = yaml.load(cfgFile)
        cfgFile.close()

        ctx = ssl.create_default_context()
        ctx.check_hostname = False
        ctx.verify_mode = ssl.CERT_NONE
        opener = urllib2.build_opener(urllib2.HTTPSHandler(context=ctx))
        if self.data == '':
            request = urllib2.Request('https://' + cfg["nessus"]["server"] +
                                      ':' + cfg["nessus"]["port"] +
                                      str(self.url))
        else:
            request = urllib2.Request('https://' + cfg["nessus"]["server"] +
                                      ':' + cfg["nessus"]["port"] +
                                      str(self.url),
                                      data=self.data)
        request.add_header(
            'X-ApiKeys', 'accessKey=' + str(cfg["nessus"]["accessKey"]) +
            '; secretKey=' + str(cfg["nessus"]["secretKey"]))
        request.add_header('Content-Type', 'application/json')

        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.settimeout(1.0)
            s.connect((cfg["nessus"]["server"], cfg["nessus"]["port"]))
        except Exception as e:
            s.close()
            dir_path = os.path.dirname(os.path.realpath(__file__)) + "/.."
            logger.write(
                str(datetime.now()) + " ERROR " + str(e) +
                ". Can not connect to Nessus API. Exiting.",
                dir_path + cfg['logger']['log'])
            sys.exit()

        reply = opener.open(request).read().decode('utf8')
        self.data = ''
        try:
            return json.loads(reply)
        except:
            return reply
Beispiel #5
0
######################################
#  voice-assistant  >  main.py
#  Created by Uygur Kiran on 2021/4/16
######################################
from Core.Asistan import Asistan
from configurator import get_config
######################################

## PROPS
asistan = Asistan()

######################################
# DEBUG
######################################
if get_config("debug_mode"):
    asistan.print_devices()

######################################
# INIT
######################################
asistan.start_ui()

Beispiel #6
0
 def __init__(self):
     self.TOKEN = os.environ.get("WEATHER_TOKEN")
     self.cityName = get_config("services", "weather", "cityName")
     self.lat = get_config("services", "weather", "latitude")
     self.lon = get_config("services", "weather", "longitude")
Beispiel #7
0
def main():

    while True:

        print("0 - Show working files info")
        print("1 - Make ''look like'' file")
        print("2 - Make synonym file from alias file and lookslike file")
        print("3 - Process DREGs")
        print("4 - Run Clicker")
        print("5 - Run clicker for failed lines")
        print("6 - Update dreg file")
        print("7 - update one DREG")

        answer = input("->")

        if answer == '0':

            print_file_info(os.path.join(FN.DATA_FOLDER, 'exportdreg.xlsx'),
                            Modes.DREG_FILE)
            print_file_info(os.path.join(FN.DATA_FOLDER, 'updatedreg.xlsx'),
                            Modes.DREG_FILE)
            print_file_info(os.path.join(FN.DATA_FOLDER, 'lookslike.xlsx'))
            print_file_info(os.path.join(FN.DATA_FOLDER, 'alias.xlsx'))
            print_file_info(os.path.join(FN.DATA_FOLDER, 'alias.xlsx'))

        elif answer == '1':

            #print("Max difference between words in %  [0..100]?")
            #answer = input("->")
            answer = 0.35

            lookslike_df = pd.read_excel(
                wrk_file(FN.DATA_FOLDER, 'lookslike.xlsx'))
            alias_df = pd.read_excel(wrk_file(FN.DATA_FOLDER, 'alias.xlsx'))
            dreg_df = pd.read_excel(wrk_file(FN.DATA_FOLDER,
                                             'exportdreg.xlsx'))

            all_customer_names = DregData.customer_name_list_all(dreg_df)
            all_customers_status_new = DregData.customer_name_list_status_new(
                dreg_df)

            lookslike_df = ccm.process_lookslike(lookslike_df,
                                                 all_customer_names,
                                                 all_customers_status_new,
                                                 float(answer) / 100, alias_df)

            output_file_name = wrk_file(FN.DATA_FOLDER,
                                        'lookslike.xlsx',
                                        is_timestamp=True)
            writer = pd.ExcelWriter(output_file_name, engine='xlsxwriter')
            lookslike_df.to_excel(writer, index=False)
            writer.save()

            print(
                "Open lookslike_XXX.xlsx; fix question marks and save as lookslike.xlsx"
            )

        elif answer == "2":

            lookslike_df = pd.read_excel(
                wrk_file(FN.DATA_FOLDER, 'lookslike.xlsx'))
            alias_df = pd.read_excel(wrk_file(FN.DATA_FOLDER, 'alias.xlsx'))

            #try:
            synonyms_df = ccm.process_alias(lookslike_df, alias_df)
            #except Exception as e:
            #    print(e)

            output_file_name = wrk_file(FN.DATA_FOLDER,
                                        'synonyms.xlsx',
                                        is_timestamp=True)
            writer = pd.ExcelWriter(output_file_name, engine='xlsxwriter')
            synonyms_df.to_excel(writer, index=False)
            writer.save()

            print("Check latest synonym_XXX")

        elif answer == '3':

            synonyms_df = pd.read_excel(
                wrk_file(FN.DATA_FOLDER, 'synonyms.xlsx'))
            dreg_df = pd.read_excel(wrk_file(FN.DATA_FOLDER,
                                             'exportdreg.xlsx'))

            q = count_synonym_file_questions(synonyms_df)
            print('{} of ? in synonyms'.format(q))
            if q > 0:
                print(
                    "Open synonym_XXX.xlsx; fix question marks and save as synonym.xlsx"
                )
                continue

            core_part_name_df = pd.read_excel(
                wrk_file(FN.DATA_FOLDER, "coreproduct.xlsx"))
            core_part_name_df = core_part_name_df[['Type', 'Core Product']]
            core_product_list = core_part_name_df['Core Product'].tolist()
            core_part_name_dict = core_part_name_df.set_index(
                'Type')['Core Product'].to_dict()
            for cp in core_product_list:
                if cp not in core_part_name_dict:
                    core_part_name_dict.update({cp: cp})

            synonyms_dict = ccm.get_dict(synonyms_df)

            dd = DregData(dreg_df, synonyms_dict, core_part_name_dict)

            solver = DregSolver()

            solver.process_all_new(dd)

            solver.process_duplication_check(dd)

            writer = DregWriter()
            writer.set_default_rules()

            output_file_name = wrk_file(FN.DATA_FOLDER,
                                        "dreg_analysis.xlsx",
                                        is_timestamp=True)
            writer.save_dreg(output_file_name, dd)

            print("Done!")

            print(solver.get_statistics())

        elif answer == "4":

            mylog.info('Starting update IDIS...')

            mylog.debug("Reading 'dreg_analysis.xlsx' file")
            dreg_df = pd.read_excel(
                wrk_file(FN.DATA_FOLDER, 'dreg_analysis.xlsx'))

            mylog.debug("Init DregData database...")
            dd = DregData(dreg_df, add_working_columns=False)

            dreg_ids_with_action = dd.id_list_action_not_empty

            #dreg_ids_with_action = ['20408789']
            mylog.debug("Staring IDIS update with {0} registrations...".format(
                len(dreg_ids_with_action)))
            update_idis(dd, dreg_ids_with_action, get_config('idis'))

            output_file_name = wrk_file(FN.DATA_FOLDER,
                                        "last_clicker_result.xlsx",
                                        is_timestamp=True)
            writer = pd.ExcelWriter(output_file_name, engine='xlsxwriter')
            dreg_df.to_excel(writer, index=False)
            writer.save()
            # run_idis_clicker(dd, dreg_ids_with_action)

        elif answer == "5":
            dreg_df = pd.read_excel(
                wrk_file(FN.DATA_FOLDER, 'dreg_analysis.xlsx'))
            dd = DregData(dreg_df)
            dreg_ids_with_action = dd.id_list_clicker_fail()
            run_idis_clicker(dd, dreg_ids_with_action)

        elif answer == "6":

            p_old_file = os.path.join(FN.DATA_FOLDER, 'exportdreg.xlsx')
            p_new_file = os.path.join(FN.DATA_FOLDER, 'updatedreg.xlsx')

            print_file_info(p_old_file, mode=Modes.DREG_FILE)
            print_file_info(p_new_file, mode=Modes.DREG_FILE)

            print("Result will be saved in exportdreg.xlsx")
            is_yes = input("Continue y/n?")
            if is_yes == 'y':
                init = pd.read_excel(p_old_file)
                upd = pd.read_excel(p_new_file)

                init_dd = DregData(init, add_working_columns=False)
                upd_dd = DregData(upd, add_working_columns=False)

                init_dd.update(upd_dd)

                output_df = init_dd.get_dreg_data()

                output_file_name = wrk_file(FN.DATA_FOLDER, "exportdreg.xlsx")
                writer = pd.ExcelWriter(output_file_name, engine='xlsxwriter')
                output_df.to_excel(writer, index=False)
                writer.save()

                print("Done!")

                print_file_info(p_old_file, mode=Modes.DREG_FILE)
        elif answer == "7":
            mylog.info('Starting update one DREG...')
            dreg_id = str(input("DREG ID:"))

            mylog.debug("Reading 'dreg_analysis.xlsx' file")
            dreg_df = pd.read_excel(
                wrk_file(FN.DATA_FOLDER, 'dreg_analysis.xlsx'))

            mylog.debug("Init DregData database...")
            dd = DregData(dreg_df, add_working_columns=False)

            dreg_ids_with_action = [dreg_id]
            mylog.debug("Staring IDIS update with {0} registrations...".format(
                len(dreg_ids_with_action)))
            update_idis(dd, dreg_ids_with_action, get_config('idis'))

        elif answer == "q":
            break
Beispiel #8
0
 def __init__(self):
     self.lang = get_config("speechGeneration", "language")
     self.tld = get_config("speechGeneration", "tld")
     self.slow_talk = get_config("speechGeneration", "slow_talk")
Beispiel #9
0
 def __init__(self):
     self.name = get_config("personalization", "user", "name")