Usage

Note

The Doomsday Clock doesn’t change often — at most once a year — and offers no API. Since this package relies on web scraping of TheBulletin.org, please do consider throttling/caching your requests.

Command-line interface

Example usage:

 $ countdoom

  11 12   ️
 10 \|      Countdoom: Doomsday Clock 🤯 🌊 ☢️ ☠️
 9   @      World threat assessment from TheBulletin.org

  Sentence: IT IS 2 MINUTES TO MIDNIGHT
     Clock: 11:58
      Time: 23:58:00
   Minutes: 2
   Seconds: 120
 Countdown: 120 seconds

Example usage using a single format (e.g. clock):

 $ countdoom --format clock

 11:58

Built-in help:

 $ countdoom -h

  11 12   ️
 10 \|      Countdoom: Doomsday Clock 🤯 🌊 ☢️ ☠️
 9   @      World threat assessment from TheBulletin.org

 usage: countdoom [--format {sentence,clock,time,minutes,countdown,all,json}]
                  [--timeout TIMEOUT] [--v] [-h]

 optional arguments:
   --format {sentence,clock,time,countdown,all,json}
                         return data format (default: all).
   --timeout TIMEOUT     connection/request timeout in seconds (default: 10).
   --v, --version        show program's version number and exit
   -h, --help            show this help message and exit

 "Be the change you want to see in the world." —Gandhi/Arleen Lorrance

Python import

To use Countdoom in a project:

import countdoom

Get the current Doomsday Clock value using the event loop:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import asyncio
from typing import Dict, Union

from countdoom import CountdoomClient


def get_doomsday_clock() -> Dict[str, Union[str, float, None]]:
    """
    Get current Doomsday Clock value.

    :return: Dictionary of Doomsday Clock representation styles
    """
    client = CountdoomClient()
    loop = asyncio.get_event_loop()
    task = loop.create_task(client.fetch_data())
    data = loop.run_until_complete(task)
    return data

Get the current Doomsday Clock value using an awaitable:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from typing import Dict, Union

from countdoom import CountdoomClient


async def async_get_doomsday_clock() -> Dict[str, Union[str, float, None]]:
    """
    Get current Doomsday Clock value using AsyncIO.

    :return: Dictionary of Doomsday Clock representation styles
    """
    client = CountdoomClient()
    data = await client.fetch_data()
    return data