graphai.core.common.common_utils module

graphai.core.common.common_utils.make_sure_path_exists(path, file_at_the_end=False, full_perm=True)

Recursively creates the folders in a path. :param path: The path that needs to exist (and will thus be created if it doesn’t) :param file_at_the_end: Whether there is a filename at the end of the path :param full_perm: If set, the function will assign full permission (chmod 777) to each newly created folder

Returns:

None

graphai.core.common.common_utils.file_exists(file_path)

Checks whether a given file exists :param file_path: Path of the file

Returns:

True if file exists, False otherwise

graphai.core.common.common_utils.write_text_file(filename_with_path, contents)

Writes contents to text file :param filename_with_path: Full path of the file :param contents: Textual contents

Returns:

None

graphai.core.common.common_utils.write_json_file(filename_with_path, d)

Writes dictionary to JSON file :param filename_with_path: Full path of the file :param d: Dictionary to write

Returns:

None

graphai.core.common.common_utils.read_text_file(filename_with_path)

Opens and reads the contents of a text file :param filename_with_path: Full path of the file

Returns:

Contents of the file

graphai.core.common.common_utils.read_json_file(filename_with_path)

Reads the contents of a JSON file :param filename_with_path: Full path of the file

Returns:

Dictionary containing contents of the JSON file

graphai.core.common.common_utils.format_datetime_for_mysql(dt)
graphai.core.common.common_utils.parse_mysql_datetime(dt)
graphai.core.common.common_utils.get_current_datetime()

Returns current datetime formatted for MySQL :returns: Datetime string

graphai.core.common.common_utils.invert_dict(d)
graphai.core.common.common_utils.strtobool(val)

Convert a string representation of truth to True or False. True values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; False values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’. Raises ValueError if ‘val’ is anything else. Case-insensitive.

graphai.core.common.common_utils.copy_file_within_folder(folder_name, src_file, dest_file)
graphai.core.common.common_utils.convert_list_to_text(str_or_list)
graphai.core.common.common_utils.convert_text_back_to_list(s, return_list=False)
graphai.core.common.common_utils.generate_random_token()

Generates a random string using the current time and a random number to be used as a token. :returns: Random token

graphai.core.common.common_utils.get_file_size(file_path)
graphai.core.common.common_utils.retrieve_generic_file_from_generic_url(url, output_filename_with_path, output_token)

Retrieves a generic file from a given URL using WGET and stores it locally. :param url: the URL :param output_filename_with_path: Path of output file :param output_token: Token of output file

Returns:

Output token if successful, None otherwise

graphai.core.common.common_utils.is_url(s)
graphai.core.common.common_utils.is_effective_url(s)
graphai.core.common.common_utils.is_token(s)
graphai.core.common.common_utils.is_pdf(s)
graphai.core.common.common_utils.get_most_common_element(input_list, remove_nulls=True)