utils

Functions that are used within Raider.

colored_text(text, color)[source]
default_user_agent()[source]

Gets the default user agent.

Gets the current version of Raider and creates the user agent string.

Return type

str

Returns

A string with the user agent.

get_config_dir()[source]

Gets the configuration directory.

Returns the path of the directory with the Raider configuration files.

Return type

str

Returns

A string with the path of the configuration directory.

get_config_file(filename)[source]

Gets the configuration file.

Given the file name, it returns the path of this file in the Raider configuration directory.

Parameters

filename (str) – A string with the name of the file to look up for in the main configuration directory.

Return type

str

Returns

A string with the path of the file.

get_project_dir(project)[source]

Gets the directory of the project.

Given the name of the project, returns the path to the directory containing the configuration files for this project.

Parameters

project (str) – A string with the name of the project.

Return type

str

Returns

A string with the path of the directory where the config files for the project are located.

get_project_file(project, filename)[source]

Gets a file from a project.

Given the project name and the file name, it returns the path to that file.

Parameters
  • project (str) – A string with the name of the project.

  • filename (str) – A string with the file name.

Return type

str

Returns

The path of the file in the project directory.

import_raider_objects()[source]

Imports Raider objects to use inside hy configuration files.

To make Raider objects visible inside hy files without using separate imports, this function does the imports and returns the locals() which is later used when evaluating hy files.

Return type

Dict[str, Any]

Returns

A dictionary with the locals() containing all the Raider objects that can be used in hy files.

hy_dict_to_python(hy_dict)[source]

Converts a hy dictionary to a python dictionary.

When creating dictionaries in hylang using :parameters they become hy.models.Keyword objects. This function converts them to normal python dictionaries.

Parameters

hy_dict (Dict[Keyword, Any]) – A dictionary created in hy, which uses hy.models.Keyword instead of simple strings as keys.

Return type

Dict[str, Any]

Returns

A dictionary with the same elements only with hy.models.Keyword keys converted into normal strings.

py_dict_to_hy_list(data)[source]

Converts a python dictionary to a hylang list.

In hy, dictionaries are created out of lists, and this function converts a normal python dictionary to a list made out of hy symbols that will be later used to create the hy dictionary.

Parameters

data (Dict[str, Any]) – A python dictionary with the data to convert.

Return type

List[Union[String, Dict, Symbol]]

Returns

A list with hy objects that can be used to create a hy dictionary.

create_hy_expression(variable, value)[source]

Creates a hy expression.

Raider configuration is saved in hy format, and this function creates the assignments in this format.

Parameters
  • variable (str) – A string with the name of the variable to be created.

  • value (Union[str, Dict[Any, Any], List[Any]]) – The value of the variable.

Return type

str

Returns

A string with the valid hy expression.

serialize_hy(form)[source]

Serializes hy expression.

This function serializes the supplied hy expression and returns it in a string format, so that it can be later saved in a file.

Parameters

form (Union[Expression, Dict, List, Symbol, Integer, Keyword, String]) – A hy expression to convert to a string.

Return type

str

Returns

A string with the serialized form.

eval_file(filename, shared_locals=None)[source]

Evaluate hy file.

This function evaluates all the content inside the supplied hy file, and returns the created locals() so that it can be later used for other files.

Parameters
  • filename (str) – A string with the file name to be evaluated.

  • shared_locals (Optional[Dict[str, Any]]) – A dictionary with the locals() that will be considered when evaluating the file.

Return type

Dict[str, Any]

Returns

A dictionary with the updated locals() after evaluating the hy file.

eval_project_file(project, filename, shared_locals)[source]

Evaluate a hy file from a project.

This function evaluates the specified file inside the project and returns the locals() which are updated after evaluating the file.

Parameters
  • project (str) – A string with the name of the project.

  • filename (str) – A string with the file name to be evaluated.

  • shared_locals (Dict[str, Any]) – A dictionary of locals() to be included when evaluating the file.

Return type

Dict[str, Any]

Returns

A dictionary of locals() updated after evaluating the file.

list_projects()[source]

List existing projects.

This function returns the list of projects that have been configured in Raider.

Return type

List[str]

Returns

A list with the strings of the project found in the configuration directory.

list_hyfiles(project)[source]

List hyfiles for a project.

This function returns the list of hyfiles that have been configured in Raider for the provided project.

Parameters

project (str) – A string with the project name.

Return type

List[str]

Returns

A list with the strings of the project found in the configuration directory.

match_tag(html_tag, attributes)[source]

Tells if a tag matches the search.

This function checks whether the supplied tag matches the attributes. The attributes is a dictionary, and the values are treated as a regular expression, to allow checking for tags that don’t have a static value.

Parameters
  • html_tag (Tag) – A bs4.element.Tag object with the tag to be checked.

  • attributes (Dict[str, str]) – A dictionary of attributes to check whether they match with the tag.

Return type

bool

Returns

A boolean saying whether the tag matched with the attributes or not.

parse_json_filter(raw)[source]

Parses a raw JSON filter and returns a list with the items.

Parameters

raw (str) – A string with the expected JSON filter.

Return type

List[str]

Returns

A list with all items found in the filter.

colored_hyfile(filename)[source]
Return type

str