countdoom package

Submodules

countdoom.cli module

Console script for Countdoom.

SPDX-License-Identifier: MIT

countdoom.cli.cli(args=None)[source][source]

Run Countdoom client.

Parameters

args (Optional[List[Any]]) – list of arguments

Return type

None

async countdoom.cli.main(args=None)[source][source]

Console script for Countdoom.

Parameters

args (Optional[List[Any]]) – list of arguments

Raises

CountdoomClientError – If an error is generated while fetching data

Return type

None

countdoom.cli.create_parser()[source][source]

Create an argument parser.

Return type

ArgumentParser

Returns

Argument parser

countdoom.cli.parse_args(parser, args)[source][source]

Feed a list of arguments into ArgumentParser for processing.

Parameters
Return type

Namespace

Returns

ArgumentParser Namespace object

countdoom.cli.print_header()[source][source]

Display a stylized header.

Return type

None

countdoom.cli.print_results(data, args)[source][source]

Display command results in a variety of formats.

Parameters
  • data (dict) – command results

  • args (Dict[str, Any]) – ArgumentParser Namespace object

Return type

None

countdoom.client module

Client module.

SPDX-License-Identifier: MIT

class countdoom.client.CountdoomClient(timeout=10)[source][source]

Bases: object

Countdoom client.

Convert Doomsday Clock data into parsable time from the Timeline page at https://thebulletin.org/doomsday-clock/past-announcements/

Based on prior Node.js work by Matt Bierner. See https://github.com/mattbierner/MinutesToMidnight

CLOCK_URL = 'https://thebulletin.org/doomsday-clock/past-announcements/'[source]
SELECTOR = '.uabb-infobox-title'[source]
REQUEST_TIMEOUT = 10[source]
CLOCK_FORMAT_LONG = '%-I:%M:%S'[source]
CLOCK_FORMAT_SHORT = '%-I:%M'[source]
TIME_FORMAT = '%H:%M:%S'[source]
__init__(timeout=10)[source][source]

Create a CountdoomClient object.

Parameters

timeout (int) – Connection/request timeout

Return type

None

property countdown[source]

Countdown to midnight.

Return type

Optional[float]

Returns

Number of seconds to midnight

property sentence[source]

Doomsday Clock sentence.

Return type

Optional[str]

Returns

Doomsday Clock sentence

clock()[source][source]

Convert countdown to midnight into a clock representation.

Return type

Optional[str]

Returns

Clock representation of a countdown to midnight

minutes()[source][source]

Convert countdown to midnight into minutes to midnight representation.

Return type

Optional[float]

Returns

Number of minutes to midnight

time(time_format='%H:%M:%S')[source][source]

Convert countdown to midnight into a time representation.

Parameters

time_format (str) – strftime() time format

Return type

Optional[str]

Returns

Time representation of a countdown to midnight

async fetch_data()[source][source]

Retrieve the parsed Doomsday Clock.

Return type

Dict[str, Union[str, float, None]]

Returns

Extracted sentence, clock, time, minutes, and countdown

async close()[source][source]

Close the HTTP connection.

Return type

None

classmethod sentence_to_countdown(sentence)[source][source]

Convert Doomsday Clock sentence to a number of seconds to midnight.

Parameters

sentence (str) – Doomsday Clock sentence

Return type

float

Returns

A countdown to midnight

Raises

AttributeError – If sentence is not matched by regex pattern

static numeric_word_to_int(word)[source][source]

Convert textual numbers into integers.

Parameters

word (str) – Textual number from zero to nine

Return type

Optional[int]

Returns

Number from 0 to 9, if any

Todo

throw exception when word not found.

static countdown_to_time(number, time_format='%H:%M:%S')[source][source]

Convert a number of seconds to midnight into a time format.

Parameters
  • number (Union[int, float]) – Number representing a countdown

  • time_format (str) – strftime() time format

Return type

str

Returns

Time representation of countdown to midnight

exception countdoom.client.CountdoomClientError[source][source]

Bases: Exception

Countdoom client general error.

Module contents

Top-level package for Countdoom.

SPDX-License-Identifier: MIT