Utils

Introduction

The utils module contains some helper functions that are used by other modules. However, they are open to be utilised as you wish.

Usage

To use the utils module:

>>> import coast_search
>>> coast_search.utils.function(to_use)

or: .. code-block:: console

>>> from coast_search import utils
>>> utils.function(to_use)

Functions

Title: utils.py Author: Ashley Williams Description: A collection of generic utility functions that are used throughout coast by various modules relating to reading and writing to files.

coast_search.utils.get_from_file(filename)

Reads a file and returns each line as a list of strings.

Notes:
  1. All double quotes are replaced with single quotes.
  2. New line (

) characters are removed.

Args:
filename: The path to the file you wish to read.
Returns:
res: A list of strings, where each string is a line in the file.
coast_search.utils.get_from_file_list(file_list)

Given a list of file names, reads from each of these and returns a dictionary with filename: list of words :param file_list: :return:

coast_search.utils.get_json_from_file(filename)

Reads a JSON file and returns as an object.

Args:
filename: The path to the JSON file you wish to read.
Returns:
res: A JSON object, generated from the contents of the file.
Err:
In the event of an error, the error is printed to the stdout.
coast_search.utils.number_of_days_past_start_date(config)

Gets the day number past the start date defined in the config (eg if the start date was a monday and today was a wednedsay the day would be 3 :param config: config file configs start_date property :return: number of days past start date