Skip to main content

A customizable bullshit generator based on Seb Pearce's 'New-Age Bullshit Generator'

Project description

nabg (New-Age Bullshit Generator)

PyPI version License: MIT Code style: black

What is it?

nabg lets you generate randomized sentences using pre-defined sentence patterns and a vocabulary. The default vocabulary and sentences are based on Seb Pearce's "New Age Bullshit Generator". You can also provide your own sentence patterns and word lists to generate customized bullshit.

Installing nabg

nabg is available on PyPI:

pip install nabg

Usage

Generating New-Age Bullshit

nabg comes with Seb Pearce's "New-Age Bullshit Generator". To generate new-age bullshit, in python you can do:

import nabg

# Generate new-age bullshit
nabg.ionize()

# List the available topics
nabg.list_topics()

# Generate 5 bullshit sentences with topic history
nabg.ionize(5, "history")

Or, you can use the CLI:

# Generate new-age bullshit
$ nabg

# List the available topics
$ nabg --list-topics

# Generate 5 bullshit sentences with topic history
$ nabg -n 5 -t history

Generating Custom Bullshit

nabg also lets you use your own sentence patterns and vocabulary to generate sentences.

from nabg import BullshitGenerator

# ---------------------------------------------------------------------------- #
# Custom sentence patterns. A dictionary with a list of patterns for each      #
# topic. All instances of ${vocabType} will be replaced with a randomly picked #
# word of type "vocabType" from the vocabulary.                                #
# ---------------------------------------------------------------------------- #

patterns = {
    "topic1": [
        "This is a ${adj} sentence.",
        "This is a ${adjPrefix}${adj} sentence."
    ],
    "topic2": [
        "We can no longer afford to live with ${nMassBad}.",
        "Without ${nMass}, one cannot ${viPerson}.",
    ],
}


# ---------------------------------------------------------------------------- #
# Custom vocabulary. A dictionary with a list of buzzwords for each type.      #
# Each type used in a sentence pattern must have at least one word in the      #
# vocabulary.                                                                  #
# ---------------------------------------------------------------------------- #

vocabulary = {
    "adj": [
        "fantastic",
        "stupid",
        "amazing",
    ],
    "adjPrefix": [
        "ultra-",
        "semi-",
    ],
    "nMass": [
        "knowledge",
        "truth",
    ],
    "nMassBad": [
        "pain",
        "suffering",
    ],
    "viPerson": [
        "exist",
        "believe",
    ],
}

# Create a bullshit generator object
bullshit_generator = BullshitGenerator(patterns, vocabulary)

# Generate custom bullshit
bullshit_generator.ionize(5, "topic1")

BullshitGenerator ensures that sentence patterns aren't repeated on multiple calls to BullshitGenerator.ionize(). If there are no unused sentence patterns remaining in the pool for the requested topic, another topic is chosen at random. This behavior can be customised by calling any of the three methods below:

# The three methods below can be used to set BullshitGenerator's behavior
# when no more unused patterns are available for the requested topic.

# Pick a different topic at random. This is the default behavior.
bullshit_generator.use_random_topic_when_out_of_patterns()

# Reset the pool. This would cause previously used patterns to repeat.
bullshit_generator.reset_pool_when_out_of_patterns()

# Raise a NoPatternsAvailableError.
bullshit_generator.raise_error_when_out_of_patterns()

When all sentence patterns across all topics have been used up, the pool is reset. This behavior can be customised by calling any of the two methods below:

# The two methods below can be used to set BullshitGenerator's behavior
# when all patterns across topics have been used up.

# Automatically reset the pool. This is the default behavior.
bullshit_generator.enable_auto_reset()

# Raise a NoPatternsAvailableError.
bullshit_generator.disable_auto_reset()

You can reset the pool manually at any time by calling:

bullshit_generator.reset_sentence_patterns()

Note: Successive calls to nabg.ionize() are not guaranteed to have distinct sentence patterns across calls (or in other words, the pool is reset after each call to nabg.ionize()). However, the sentence patterns and vocabulary for the default new-age bullshit generator can be used to create your own instance of BullshitGenerator to customize this behaviour:

from nabg import BullshitGenerator, patterns, vocabulary

# Create a BullshitGenerator object using Seb Pearce's pattern and vocabulary set
bullshit_generator = BullshitGenerator(patterns, vocabulary)

# The calls below are guaranteed to use different sentence patterns
print(bullshit_generator.ionize(3))
print(bullshit_generator.ionize(5))
print(bullshit_generator.ionize(2))

# Reset the pool
bullshit_generator.reset_sentence_patterns()

# The below call might use the same sentence pattern as one of the above calls as the pool has been reset
print(bullshit_generator.ionize())

Developing nabg

git clone https://github.com/naveen-u/nabg.git
  • Create and activate a virtual environment:
virtualenv venv
source venv/bin/activate
  • To install nabg, along with along with the tools you need to develop and run tests, run the following in your virtualenv: :
pip3 install -e .[dev]

References

  • The original New-Age Bullshit Generator by Seb Pearce - sebpearce.
  • The Python2 CLI - mcquiggi.

Authors

  • Naveen Unnikrishnan - Initial work - naveen-u

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nabg-1.0.2.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nabg-1.0.2-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file nabg-1.0.2.tar.gz.

File metadata

  • Download URL: nabg-1.0.2.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for nabg-1.0.2.tar.gz
Algorithm Hash digest
SHA256 42665a57d4a2f051208a3296d80a16542438c8a8e2325c7a20d31bdc4aa32cc5
MD5 2ce8c7ef67c3e080f95d8b2aabbb3c98
BLAKE2b-256 aa1640386aa77b150bce6e7706cdf9dc431bf8a4addec20766a58e9931c8df90

See more details on using hashes here.

File details

Details for the file nabg-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: nabg-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for nabg-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 90c0b249d4f179f12cf2681dcf45596f7a02d46ca39c5699c93bc124eec83acd
MD5 e1bc327ef711afbf7a0e4438589bc0b2
BLAKE2b-256 0bed24ef088dc8c9b631f3f6a79cffd660eac0978e6bd998dbd4b85fa7d1e4a3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page