application.integrations package#

Subpackages#

Submodules#

application.integrations.exceptions module#

Exceptions that may be raised by various integrations.

exception application.integrations.exceptions.ApiFailedError#

Bases: Exception

Exception raised when an API call fails.

This exception is intended to be used when an API request does not succeed, either due to network issues, invalid responses, or other related errors.

message#

Explanation of the error.

Type:

str

exception application.integrations.exceptions.RepoFetchFailed(url, text)#

Bases: Exception

Exception raised when a repository fetch operation fails.

url#

The URL of the repository that failed to fetch.

Type:

str

text#

The error message associated with the fetch failure.

Type:

str

exception application.integrations.exceptions.UnsupportedFileFormat(filename)#

Bases: Exception

Exception raised for unsupported file formats.

filename#

The name of the file with the unsupported format.

Type:

str

application.integrations.github module#

application.integrations.github

class application.integrations.github.CurrentRepository(repo=None)#

Bases: Repository

A class to represent the current GitHub repository.

Inherits from:

Repository

repo#

The name of the repository. If None, it will be derived from the remote URL.

Type:

str | None

issues_pending_resolution()#

Retrieves a list of issues that are pending resolution.

This method gets the date and time of the last commit in the repository and uses it to fetch the list of issues that have been resolved since that commit.

Returns:

A list of issues that are pending resolution.

Return type:

list

class application.integrations.github.Repository(owner, repo)#

Bases: object

A class to interact with a GitHub repository using the GitHub API.

url#

The URL of the GitHub repository API endpoint.

Type:

str

issues(*, filter='state=open')#

Fetches a list of issues from the GitHub repository.

Parameters:

filter (str, optional) – A query string to filter issues. Defaults to ‘state=open’.

Returns:

A list of issues from the GitHub repository.

Return type:

list

resolved_issues(since)#

Retrieve a list of resolved (closed) issues since a given date.

Parameters:

since (str) – The date in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ) from which to retrieve closed issues.

Returns:

A list of issues that have been closed since the specified date.

Return type:

list

application.integrations.github.gh_request(url)#

Sends a GET request to the specified GitHub API URL with authorization headers.

This function reads the GitHub token from a local JSON file (‘data/auth.json’) and uses it to set the ‘Authorization’ header for the request. If the request is successful (status code 2xx), the response is returned as a dictionary. If the request fails, an error message is printed and a RepoFetchFailed exception is raised.

Parameters:

url (str) – The GitHub API URL to send the GET request to.

Returns:

The JSON response from the GitHub API as a dictionary.

Return type:

dict

Raises:

RepoFetchFailed – If the request fails, this exception is raised with the URL and error message.

application.integrations.google_books module#

application.integrations.google_books

application.integrations.google_books.get(*, id)#

Fetches book information from the Google Books API using the provided book ID.

Parameters:

id (str) – The unique identifier for the book.

Returns:

A dictionary containing book information such as authors, title, subtitle,

description, industry identifiers, page count, categories, maturity rating, language, publisher, published date, and thumbnail URL.

Return type:

dict

Raises:

exceptions.ApiFailedError – If the Google Books API call fails with a status code outside the range of 200-299.

application.integrations.google_books.query(*, title='', author='')#

Query the Google Books API for books matching the given title and/or author.

Parameters:
  • title (str) – The title of the book to search for. Default is an empty string.

  • author (str) – The author of the book to search for. Default is an empty string.

Returns:

A list of dictionaries, each representing a book that matches the query.

Each dictionary contains the following keys: - ‘id’: The unique identifier of the book. - ‘authors’: A list of authors of the book. - ‘title’: The title of the book. - ‘subtitle’: The subtitle of the book (if available). - ‘description’: A description of the book (if available). - ‘industryIdentifiers’: A list of industry identifiers (e.g., ISBN) for the book. - ‘pageCount’: The number of pages in the book. - ‘categories’: A list of categories the book belongs to. - ‘maturityRating’: The maturity rating of the book. - ‘language’: The language the book is written in. - ‘publisher’: The publisher of the book. - ‘publishedDate’: The date the book was published. - ‘thumbnail’: A URL to a thumbnail image of the book cover (if available).

Return type:

list

Raises:

exceptions.ApiFailedError – If the Google Books API call fails.

application.integrations.graphql module#

application.integrations.graphql

application.integrations.graphql.get_meta_types(data_type)#

Determines the metadata types of a given GraphQL data type.

This function checks if the provided GraphQL data type is optional and/or an array. It traverses through the type to determine if it is wrapped in GraphQLNonNull or GraphQLList.

Parameters:

data_type – The GraphQL data type to be checked.

Returns:

  • The first boolean indicates if the type is optional (True if optional, False if not).

  • The second boolean indicates if the type is an array (True if it is an array, False if not).

Return type:

A tuple containing two boolean values

application.integrations.graphql.get_type(type, param_type=None)#

Extracts and returns type information from a GraphQL type.

Parameters:
  • type – The GraphQL type to extract information from. This can be a GraphQLUnionType, GraphQLObjectType, or GraphQLArgument.

  • param_type – An optional parameter that specifies the type of the parameter. This can be used to further refine the type information.

Returns:

A dictionary containing the following keys:
  • ’name’: The name of the type as a string.

  • ’type’: The refined type if param_type is provided, otherwise the original type.

  • ’union’: A boolean indicating whether the type is a GraphQLUnionType.

  • ’input’: A boolean indicating whether the type is an input type.

  • ’subtypes’: A list of subtypes or fields associated with the type.

Return type:

dict

application.integrations.graphql.print_field(field_type, field_name, field)#

Generates a GraphQL query string for a given field.

Parameters:
  • field_type (str) – The type of the field (e.g., query, mutation).

  • field_name (str) – The name of the field.

  • field (GraphQLField) – The GraphQL field object containing type and arguments.

Returns:

A formatted GraphQL query string for the specified field.

Return type:

str

application.integrations.graphql.print_type_fields(fields, indent)#

Recursively generates a string representation of GraphQL type fields with indentation.

Parameters:
  • fields (dict) – A dictionary of GraphQL fields where keys are field names and values are field definitions.

  • indent (str) – A string used for indentation to format the output.

Returns:

A formatted string representing the GraphQL type fields with proper indentation.

Return type:

str

application.integrations.graphql.schema()#

Generates a GraphQL schema and extracts queries, mutations, and types.

This function loads the GraphQL schema from the specified path, makes it executable, and then processes the queries and mutations to build a structured output containing the details of each query and mutation, including their parameters and return types.

Returns:

A dictionary containing the following keys:
  • ’mutations’: A list of mutation details.

  • ’queries’: A list of query details.

  • ’types’: A list of data types used in the schema.

Return type:

dict

application.integrations.graphql.trim_type(data_type)#

Recursively trims a GraphQL type to its core type by removing any GraphQLNonNull or GraphQLList wrappers.

Parameters:

data_type – The GraphQL type to be trimmed. It can be an instance of GraphQLNonNull, GraphQLList, GraphQLScalarType, or GraphQLObjectType.

Return type:

GraphQLScalarType | GraphQLObjectType

Returns:

The core GraphQL type, which will be either a GraphQLScalarType or GraphQLObjectType.

application.integrations.images module#

application.integrations.images

application.integrations.images.downscale(path, max_width, output_path)#

Downscale an image to a specified maximum width while maintaining aspect ratio.

Parameters:
  • path (str) – The file path to the input image.

  • max_width (int) – The maximum width to downscale the image to.

  • output_path (str) – The file path to save the downscaled image.

Returns:

True if the image was downscaled, False if the image width was already less than or equal to max_width.

Return type:

bool

application.integrations.images.extensions()#

Returns a list of common image file extensions.

Returns:

A list containing image file extensions as strings.

Return type:

list

application.integrations.models module#

application.integrations.models

application.integrations.models.extensions()#

Returns a list of file extensions commonly used for 3D models.

Returns:

A list of strings, each representing a file extension for 3D model files.

Return type:

list

application.integrations.models.to_glb(input_filename, output_filename)#

Converts a 3D mesh file to GLB format.

Parameters:
  • input_filename (str) – The path to the input 3D mesh file.

  • output_filename (str) – The path where the output GLB file will be saved.

Return type:

None

Returns:

None

Raises:

ValueError – If the input file cannot be loaded as a 3D mesh.

application.integrations.pdf module#

This module provides functionality for manipulating PDF documents.

application.integrations.pdf.create_preview(pdf_path, preview_path, page_number=0)#

Create a preview image from the first page of a PDF document.

Parameters:
  • pdf_path (str) – The path to the PDF file.

  • preview_path (str) – The path where the preview image will be saved.

  • page_number (int) – The page number to create a preview from (default is 0 for the first page).

Returns:

True if the preview was created successfully, False otherwise.

Return type:

bool

application.integrations.qrcode module#

application.integrations.qrcode

application.integrations.qrcode.generate(file_path, text, amount)#

Generates a specified amount of QR codes and saves them to a file.

Parameters:
  • file_path (str) – The path where the generated image will be saved.

  • text (str | None) – The text to encode in the QR codes. If None, a random UUID will be used.

  • amount (int) – The number of QR codes to generate.

Return type:

None

Returns:

None

application.integrations.qrcode.process(file_path)#

Processes a file to decode QR or barcodes.

Parameters:

file_path (str) – The path to the file containing the QR or barcode.

Returns:

A dictionary containing the decoded data or an error message.
  • ’data’ (str or None): The decoded data if a QR or barcode is detected, otherwise None.

  • ’error’ (str or None): An error message if no QR or barcode is detected, otherwise None.

Return type:

str

application.integrations.system module#

application.integrations.system

application.integrations.system.disk_usage()#

Retrieve disk usage information for the application and for blob storage (if it exists). If the application and blob storage are on the same disk, they are listed together.

Returns:

A list of dictionaries containing disk usage information.

Each dictionary has the following keys: - ‘name’ (str): The name of the storage (e.g., ‘Application’, ‘Blob Storage’). - ‘free’ (int): The amount of free space in bytes. - ‘used’ (int): The amount of used space in bytes. - ‘total’ (int): The total amount of space in bytes.

Return type:

list[dict]

application.integrations.videos module#

application.integrations.videos

application.integrations.videos.create_preview_from_first_frame(video_path, output_image)#

Extracts the first frame from a video file and saves it as an image.

Parameters:
  • video_path (str) – The path to the video file.

  • output_image (str) – The path where the output image will be saved.

Return type:

None

Returns:

None

application.integrations.videos.extensions()#

Returns a list of common video file extensions.

Returns:

A list of strings representing video file extensions.

Return type:

list

Module contents#

application.integrations

application.integrations.get_subsonic()#

Returns the current instance of the Subsonic client if available.

Returns:

The Subsonic client instance if initialized, otherwise None.

Return type:

subsonic.SubsonicClient | None

application.integrations.init_subsonic(url, username, password)#

Initializes the global Subsonic client with the provided credentials.

Parameters:
  • url (str | None) – The URL of the Subsonic server.

  • username (str | None) – The username for authentication.

  • password (str | None) – The password for authentication.

Raises:

SubsonicError – If any of the required parameters (url, username, password) are missing or empty.

Return type:

SubsonicClient