Skip to main content

joke tools

Project description

image

ha

A medley of joke datasets and tools.

To install: pip install ha

Examples

Joke datasets

List the datasets (keys):

import ha
list(ha.joke_datasets)
# ['reddit_jokes', 'stupidstuff', 'wocka']

Get a dataset. The datasets are lists of dicts.

reddit_jokes = ha.joke_datasets['reddit_jokes']
reddit_jokes[1000:1003]
[{'body': 'Why did the chicken cross the road? ...',
'id': '5tdwk4',
'score': 1,
'title': 'Why did the chicken cross the road?'},
{'body': 'A little boy goes to his dad and asks, ..."',
'id': '5tdssi',
'score': 123,
'title': 'What is Politics?'},
{'body': 'A teacher asked her 4th grade students a ...',
'id': '5tdsmb',
'score': 40,
'title': 'A teacher asked her students...'}]

The values of the joke_datasets mapping are lists of dicts containing the joke data. For example, to list the datasets and their sizes, you'd do:

print({k: len(v) for k, v in ha.joke_datasets.items()})
# {'reddit_jokes': 194553, 'stupidstuff': 3773, 'wocka': 10019}

Get an aggregate of all the datasets.

len(jokes)
208345

The keys of the aggregate come as (dataset_name, id) pairs. Let's look at the first two and the first last keys.

print(list(jokes)[:2])
print(list(jokes)[-2:])
[('reddit_jokes', '5tz52q'), ('reddit_jokes', '5tz4dd')]
[('wocka', 18199), ('wocka', 18200)]

Get a joke (data) by using it's key:

jokes['wocka', 18199]

Joke (vendorized) tools

pyjokes

Install: pip install ha[pyjokes] (or independently, doing pip install pyjokes).

from ha.pyjokes import get_joke
get_joke()  # gets a random joke, with default characteristics

"Two bytes meet. The first byte asks, 'Are you ill?' The second byte replies, 'No, just feeling a bit off.'"

laugh

import laugh
thor_joke = laugh.NamedJokes(name='Thor')
thor_joke()  # random joke
'The stock market monitors Thor.'
thor_joke('god')  # random joke containing the word "god" (or None if none found)
'The guy that God prays to goes to Thor for forgiveness!'

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

ha-0.0.8.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

ha-0.0.8-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

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