bibliometa.utils package

Submodules

bibliometa.utils.archives module

This module provides utilities to handle tar files.

bibliometa.utils.archives.tar(path, name)[source]

Put contents from path to tar.gz archive in name.

bibliometa.utils.utils module

This module provides utility classes and functions whose usage is not limited to a specific context.

class bibliometa.utils.utils.DictUtils[source]

Bases: object

The DictUtils provides generic utilities.

static get_top_keys(d, k)[source]

Get keys with highest values from a dictionary.

Parameters
  • d (dict) – A dictionary

  • k (int) – Top k elements that will be returned

Returns

List of tuples (value, key) for top k keys

Return type

list

static merge(a, b)[source]

Merge two dictionaries.

Parameters
  • a (dict) – A dictionary

  • b (dict) – Another dictionary

Raise

KeyError if a key is found in both dictionaries

Returns

Dictionary a merged with b

Return type

dict

static read_from_json(f, encoding='utf-8')[source]

Read a dictionary from a JSON file.

Parameters
  • f (str) – Path to file

  • encoding (str) – File encoding

Returns

Dictionary loaded from JSON file

Return type

dict

Raises

FileNotFoundError – If f does not point to a file

static remove_empty_entries(d)[source]

Remove keys from dict d that have no values.

Parameters

d (dict) – A dictionary

Returns

Input dictionary without empty entries.

Return type

dict

static remove_keys(i, o, k, encoding='utf-8')[source]

Remove all keys from a given dict i (in a JSON file) if not in k and save the remaining dict as JSON in o.

Parameters
  • i (str) – Path to input JSON file

  • o (str) – Path to output JSON file

  • k (list) – List of keys to be removed

  • encoding (str) – File encoding

static save_to_json(d, f, encoding='utf-8')[source]

Save a dictionary to a JSON file.

Parameters
  • d (dict) – A dictionary

  • f (str) – Path to file

  • encoding (str) – File encoding

Raises

FileNotFoundError – If f does not point to a file

static sort_by_key(d)[source]

Sort a dictionary alphabetically by its keys.

Parameters

d (dict) – A dictionary

Returns

The sorted dictionary

Return type

dict

class bibliometa.utils.utils.MainUtils[source]

Bases: object

The MainUtils provides generic utilities.

static get_factor(size)[source]

Calculate factor to keep max value of progress bar below 100.

Parameters

size (int) – Number of total values

Returns

Factor by which number of values needs to be divided

Return type

int

static get_file_info(path, suffix='')[source]

Get filename, suffix and file extension from a path.

Parameters
  • path (str) – Path to a file

  • suffix (str) – Suffix that should be added to a filename (optional)

Returns

Filename, suffix and file extension

Return type

tuple of str

Module contents

Utilities package for Bibliometa.