コード例 #1
0
def set_config():
    if opt.config:
        config = parse_config(opt.config)
    else:
        raise_exception('--config must be specified.')

    if isinstance(config.DATA.SCALE, int):
        config.DATA.SCALE = (config.DATA.SCALE, config.DATA.SCALE)  # make tuple

    if not opt.tag:
        opt.tag = utils.get_file_name(opt.config)


    if opt.local_rank is not None:
        opt.gpu_id = opt.local_rank

    opt.device = 'cuda:' + str(opt.gpu_id) if torch.cuda.is_available() and opt.gpu_id != -1 else 'cpu'

    if opt.debug:
        config.MISC.SAVE_FREQ = 1
        config.MISC.VAL_FREQ = 1
        config.MISC.LOG_FREQ = 1

    if opt.tag != 'default':
        pid = f'[PID:{os.getpid()}]'
        with open('run_log.txt', 'a') as f:
            f.writelines(utils.get_time_str(fmt="%Y-%m-%d %H:%M:%S") + ' ' + pid + ' ' + get_command_run() + '\n')

    return config
コード例 #2
0
ファイル: user_feed_menu.py プロジェクト: PlatonGit/blog2
class UserFeedMenu(BaseMenu):
    __menu_heading = '\n' + '=' * 10 + ' | My feed | ' + '=' * 10
    __options = '[1] Back to main menu'
    __next_menus = {
        '1': lambda *_: raise_exception(ExitFromMenuException),
    }

    def __init__(self, user_controller, profile_controller, post_controller):
        self.__user_controller = user_controller
        self.__profile_controller = profile_controller
        self.__post_controller = post_controller

    def display(self):
        input_func = get_option_input()

        def get_input():
            print(self.__menu_heading)
            print(self.__options)

            selected_option = input_func('\nEnter option\'s id: ')
            if selected_option not in self.__next_menus.keys():
                raise UserInputOptionException
            return selected_option

        while True:
            selected_option = self.input_secure_wrap(get_input)

            try:
                next_menu = self.__next_menus[selected_option](
                    self.__user_controller, self.__profile_controller,
                    self.__post_controller)
                next_menu.display()
            except ExitFromMenuException:
                return
コード例 #3
0
ファイル: start_menu.py プロジェクト: PlatonGit/blog2
class StartMenu(BaseMenu):
    __menu_heading = '\n' + '=' * 10 + ' | Start Menu | ' + '=' * 10
    __options = '[1] Log in\n[2] Sign up\n[3] Exit'
    __next_menus = {
        '1': LoginMenu,
        '2': RegistrationMenu,
        '3': lambda *_: raise_exception(UserExitException)
    }

    def __init__(self, user_controller, profile_controller, post_controller):
        self.__user_controller = user_controller
        self.__profile_controller = profile_controller
        self.__post_controller = post_controller

    def display(self):
        input_func = get_option_input()

        def get_input():
            print(self.__menu_heading)
            print(self.__options)

            selected_option = input_func('\nEnter option\'s id: ')
            if selected_option not in self.__next_menus.keys():
                raise UserInputOptionException
            return selected_option

        while True:
            selected_option = self.input_secure_wrap(get_input)

            next_menu = self.__next_menus[selected_option](
                self.__user_controller, self.__profile_controller,
                self.__post_controller)
            next_menu.display()
コード例 #4
0
ファイル: main_menu.py プロジェクト: S-Q-E/recipe-app
class MainMenu(BaseMenu):
    header = "******Main Menu******"
    options = '[1] - Create recipe\n[2] - Recipe list\n[3] - Delete recipe\n[4] - Exit'
    next_menus = {
        '1': CreateRecipe,
        '2': RecipeList,
        '3': DeleteRecipe,
        '4': lambda: raise_exception(KeyboardInterrupt)
    }


    def show(self):
        input_func = get_option_input()

        def get_input():
            selected_option = input_func('Enter option')
            if selected_option not in self.next_menus.keys():
                raise UserInputOptionException
            return selected_option

        while True:
            print(self.header)
            print(self.options)

            selected_option = self.input_secure_wrap(get_input)

            next_menu = self.next_menus[selected_option]()
            
            next_menu.show()
コード例 #5
0
ファイル: login_menu.py プロジェクト: 1zycodr/blog
    def __init__(self, user_controller, profile_controller, post_controller):
        self.__user_controller = user_controller
        self.__profile_controller = profile_controller
        self.__post_controller = post_controller

        self.__next_menus = {
            '1': lambda *_: None,
            '2': lambda *_: raise_exception(ExitFromMenuException)
        }
コード例 #6
0
class RecipeList(BaseMenu):
    header = "*****Recipe List*****"
    options = "[1] Exit"
    next_menus = {'1': lambda *_: raise_exception(ExitFromMenuException)}

    def show(self):
        print(self.header)

        recipes = select_all_recipes()

        for i in recipes:
            recipe = i['recept']
            ingredients = i['ingredients']
            print(f"Name: {recipe}\nIngredients: {ingredients}")

        input("Press Enter to exit")
コード例 #7
0
ファイル: main_menu.py プロジェクト: PlatonGit/blog2
class MainMenu(BaseMenu):
    __menu_heading = '\n' + '=' * 10 + ' | Main Menu | ' + '=' * 10
    __options = '[1] My profile\n[2] My page\n[3] My feed\n[4] Log out'
    __next_menus = {
        '1': ProfileMenu,
        '2': UserPageMenu,
        '3': UserFeedMenu,
        '4': lambda *_: raise_exception(ExitFromMenuException)
    }


    def __init__(self, user_controller, profile_controller, post_controller):
        self.__user_controller = user_controller
        self.__profile_controller = profile_controller
        self.__post_controller = post_controller
        self.__context = Context()

    
    def display(self):
        print(f'\nWelcome, {self.__context.user.username}!')
        
        input_func = get_option_input()

        def get_input():
            print(self.__menu_heading)
            print(self.__options)
            
            selected_option = input_func('\nEnter option\'s id: ')
            if selected_option not in self.__next_menus.keys():
                raise UserInputOptionException
            return selected_option

        while True:
            selected_option = self.input_secure_wrap(get_input)

            try:
                next_menu = self.__next_menus[selected_option](
                    self.__user_controller,
                    self.__profile_controller,
                    self.__post_controller
                )
                next_menu.display()
            except ExitFromMenuException:
                return
コード例 #8
0
ファイル: start_menu.py プロジェクト: almat-kst/python_blog
class StartMenu(BaseMenu):
    __header = '-' * 10 + ' Blog ' + '-' * 10
    __options = '[1] - Enter in\n[2] - Registration\n[3] - Exit'
    __next_menus = {
        '1': LoginMenu,
        '2': RegistrationMenu,
        '3': lambda *_: raise_exception(KeyboardInterrupt)
    }

    def __init__(self, user_controller, profile_controller, post_controller):
        self.__user_controller = user_controller
        self.__profile_controller = profile_controller
        self.__post_controller = post_controller

    def show(self):
        input_func = get_option_input()

        def get_input():
            selected_option = input_func('Enter option: ')
            if selected_option not in self.__next_menus.keys():
                raise UserInputOptionException
            return selected_option
        
        while True:
            print(self.__header)
            print(self.__options)

            selected_option = self.input_secure_wrap(get_input)
            
            next_menu = self.__next_menus[selected_option](
                self.__user_controller,
                self.__profile_controller, 
                self.__post_controller
            )
            try:
                next_menu.show()
            except ExitFromMenuException:
                pass
コード例 #9
0
def extract_recording_metadata(
    recording_boxes: List[WebElement],
    driver: WebDriver,
    old_metadata: List[Dict[str, Any]],
    download_duplicates: bool,
) -> Tuple[List[Dict[str, Any]], List[int]]:
    """
    For each recording, extracts the message text, date of message, time of message, device on which the message
    was sent, and the div_id which acts as a unique identifier for each recording.

    :param recording_boxes:
    :param driver:
    :param old_metadata:
    :param download_duplicates:

    :return: Outputs a tuple of two things:
        [0]: A list of all of the metadata for all of the recordings.
        [1]: A list of indices of which recordings need to be downloaded (and which can be skipped).
    """
    print_log("Extracting the metadata from each recording: ")
    recording_metadata = []
    indices_to_download = []
    num_recordings = len(recording_boxes)
    print_log(f"Total recordings: {num_recordings}.")

    num_skipped_recordings = 0

    for i, recording_box in enumerate(recording_boxes):
        box_div_id = recording_box.get_property("id")

        # Skip this recording if it is already documented.
        if download_duplicates is False:
            old_metadata_info = find_div_id_in_metadata(
                box_div_id, old_metadata)
            if old_metadata_info is not None:
                recording_metadata.append(old_metadata_info)
                print_log(f"Skipping recording #{i + 1}.")
                continue

        print_log(f"Working on recording #{i + 1}.")
        recording_date = ""
        recording_time = ""
        recording_device = ""

        message_div = recording_box.find_elements_by_xpath(
            ".//div[@class='record-summary-preview customer-transcript']")

        if len(message_div) == 0:
            audio_not_understood_msg = recording_box.find_elements_by_xpath(
                ".//div[@class='record-summary-preview replacement-text']")

            if len(audio_not_understood_msg) == 0:
                print_log(
                    "Cannot seem to find the transcription of the recording. Going to skip this recording."
                )
                num_skipped_recordings += 1
                continue
            else:
                message_div = audio_not_understood_msg

        recording_text = message_div[0].text

        date_time_info = recording_box.find_elements_by_xpath(
            ".//div[@class='item']")
        if len(date_time_info) < 3:
            print_log(
                "ERROR: The recording div does not seem to have ALL of the following info: "
                "Date, Time, and device. Going to error out.")
            raise_exception(
                NoSuchElementException(
                    "The recording div does not have all the necessary "
                    "metadata for extraction, or the page layout has changed."
                ),
                driver,
            )
        else:
            recording_date = date_time_info[0].text
            recording_time = date_time_info[1].text
            recording_device = date_time_info[2].text

        metadata = {
            "message": recording_text,
            "date": recording_date,
            "time": recording_time,
            "device": recording_device,
            "div_id": box_div_id,
        }
        recording_metadata.append(metadata)
        indices_to_download.append(i - num_skipped_recordings)

        # Open box for audio ID extraction later
        expand_button_list = recording_box.find_elements_by_xpath(".//button")
        if len(expand_button_list) == 0:
            print_log(
                "ERROR: The script cannot find the button to expand the recording box. This means that "
                "this recording cannot be extracted (but the metadata can still be)."
            )
        else:
            expand_button_list[0].click()
            driver.implicitly_wait(1)
            time.sleep(1)

    return recording_metadata, indices_to_download