Giter Club home page Giter Club logo

jokes's Introduction

          _____                   _______                   _____                    _____                    _____
         /\    \                 /::\    \                 /\    \                  /\    \                  /\    \
        /::\    \               /::::\    \               /::\____\                /::\    \                /::\    \
        \:::\    \             /::::::\    \             /:::/    /               /::::\    \              /::::\    \
         \:::\    \           /::::::::\    \           /:::/    /               /::::::\    \            /::::::\    \
          \:::\    \         /:::/~~\:::\    \         /:::/    /               /:::/\:::\    \          /:::/\:::\    \
           \:::\    \       /:::/    \:::\    \       /:::/____/               /:::/__\:::\    \        /:::/__\:::\    \
           /::::\    \     /:::/    / \:::\    \     /::::\    \              /::::\   \:::\    \       \:::\   \:::\    \
  _____   /::::::\    \   /:::/____/   \:::\____\   /::::::\____\________    /::::::\   \:::\    \    ___\:::\   \:::\    \
 /\    \ /:::/\:::\    \ |:::|    |     |:::|    | /:::/\:::::::::::\    \  /:::/\:::\   \:::\    \  /\   \:::\   \:::\    \
/::\    /:::/  \:::\____\|:::|____|     |:::|    |/:::/  |:::::::::::\____\/:::/__\:::\   \:::\____\/::\   \:::\   \:::\____\
/\:::\  /:::/    \::/    / \:::\    \   /:::/    / \::/   |::|~~~|~~~~~     \:::\   \:::\   \::/    /\:::\   \:::\   \::/    /
 \:::\/:::/    / \/____/   \:::\    \ /:::/    /   \/____|::|   |           \:::\   \:::\   \/____/  \:::\   \:::\   \/____/
  \::::::/    /             \:::\    /:::/    /          |::|   |            \:::\   \:::\    \       \:::\   \:::\    \
   \::::/    /               \:::\__/:::/    /           |::|   |             \:::\   \:::\____\       \:::\   \:::\____\
    \::/    /                 \::::::::/    /            |::|   |              \:::\   \::/    /        \:::\  /:::/    /
     \/____/                   \::::::/    /             |::|   |               \:::\   \/____/          \:::\/:::/    /
                                \::::/    /              |::|   |                \:::\    \               \::::::/    /
                                 \::/____/               \::|   |                 \:::\____\               \::::/    /
                                  ~~                      \:|   |                  \::/    /                \::/    /
                                                           \|___|                   \/____/                  \/____/

What is it?

A small CLI app for fetching and displaying jokes on your terminal ๐Ÿคก

Jokes are taken from the public JokeAPI. A lot of the jokes on there are VERY dark and likely to be insulting. It is possible to filter out some of the gutter humor (but why tho? gutter humor is the best humor). To filter jokes, see the flag section.

How to use it

Jokes has three dependencies that will have to be installed prior to running locally.

  1. poetry
  2. pre-commit
  3. just

Once all three have been installed, clone this repo and "cd" your way into the created folder, e.g. cd jokes.

To setup the environment run just setup, and activate the virtual environment created by poetry with poetry shell.

You should now be able to run the jokes command. Try it out by running jokes get.

Options (arguments)

There are a few arguments you can use when calling jokes.

Category

Example: jokes get -c Any or jokes get --category Any

Default: Any

The category tag will specify which category your joke will be in. Use jokes get --help to see available categories.

Type

Example: jokes get -t Single or jokes get --type Single

Default: Random

Choose the type of joke, either a single oneliner or a two-parter. Use jokes get --help to see available types.

Flag

Example: jokes get -f nsfw -f explicit or jokes get --flag nsfw

Default: []

The flag option can be used once, multiple times, or not at all. It is used to try to filter out unwanted jokes. But it isn't an exact science, so don't be surprised if it doesn't filter out everything.

Use jokes get --help to see available flags.

Lang

Example: jokes get -l fr or jokes get --lang fr

Default: EN (English)

Choose the language you want your joke to be in. Choice must be in the ISO 639-1 format. Current supported languages are English, French, Portuguese, Czech, Spanish, and German.

Note that the option does not translate the jokes but filters jokes that have been submitted in the desired language.

Safe Mode

Example: jokes get --safe or jokes get --unsafe

Default: unsafe

If you use the safe option, the API will attempt to filter out any offensive, dark, or insulting jokes. Be warned that some gutter humor may work its way through the filtering, but it's unlikely.

Coming Soon(ish)

The ability to submit a joke to the Joke API with this CLI is currently under construction ๐Ÿ› ๏ธ. The code has been written but it hasn't been possible to test since the Joke API has temporarily disabled joke submissions at this time.

Development

Debug

Example: jokes --debug

Default: Off

Debug is turned off by default but can be turned on using the debug flag.

Errors are typically returned as "An unexpected error occurred." If you wish to see more information about the nature of the error, use the debug flag. This is only intended for development purposes.

Testing

Tests are written in pytest and can be called using either just test while the virtual environemnt is activated.

jokes's People

Contributors

te25son avatar

Watchers

 avatar

jokes's Issues

Add safe mode to get request

The Joke API has a "safe-mode" that tries to filter out any unsafe / insulting jokes. It would be nice to have the functionality work with the CLI.

This would require adding another option to the get command. Perhaps another context flag?

@click.option("--safe/--not-safe", "safe", default=False)

ctx.obj["SAFE"] = safe

The biggest problem I see is with httpx; the library doesn't support creating valueless query parameters.

params = {"safe-mode": None}
r = httpx.get("https://v2.jokeapi.dev/joke/ANY", params=params)

# OUTPUT:
# https://v2.jokeapi.dev/joke/ANY?safe-mode=

params = {"safe-mode": ""}
r = httpx.get("https://v2.jokeapi.dev/joke/ANY", params=params)

# OUTPUT:
# https://v2.jokeapi.dev/joke/ANY?safe-mode=

In both cases, the parameter is appended with an =, and this syntax is not valid in the Joke API. Calling the endpoint https://v2.jokeapi.dev/joke/DARK?safe-mode properly filters out the unsafe jokes, but calling https://v2.jokeapi.dev/joke/DARK?safe-mode= with the appended = does not.

On top of this, manually adding safe-mode to the url doesn't work either since httpx will overwrite any existing query parameters.

params = {"type": "SINGLE"}
r = httpx.get("https://v2.jokeapi.dev/joke/ANY?safe-mode", params=params)

# OUTPUT
# https://v2.jokeapi.dev/joke/ANY?type=SINGLE

A possible solution is to create the url ourselves with something like

params = {
    "type": data.type,
    "blacklistFlags": "+".join(data.flags),
    "safe-mode": None
}
formatted_params = "&".join([k if v is None else f"{k}"="{v}" for k, v in params.items()])

with Client() as client:
    response = client.get("https://v2.jokeapi.dev/joke/{data.category}?{formatted_params}")

^ in this case the params can't be added to the client either because it will automatically format them, removing any parameters without an =.

Double validation in submit pipeline

There is a performance downgrade introduced in #19 .

Due to the inheritance of JokeSingleSubmit + the workflow of using JokeBase to match the joke type, "type" and "category" are validated twice in the submit pipeline.

Screen Shot 2022-08-07 at 4 10 21 PM

Increase code coverage percentage to 100%

#27 introduced code coverage in the test pipeline, but limited it 85% so the tests would pass and the PR could be merged.

Ideally we would want this percentage to be 100%, so we should improve the tests, cover the areas that aren't covered and increase the expected percentage in pyproject.toml to 100%

Tests and documentation for utils

#22 was resolved, but there are no tests or documentation for the features that were added.

Tests should be created for the new features added by #23 and the README should be updated.

  • Add tests
  • Update documentation

Write Better Tests

The current tests were made with the simple idea "any tests are better than no tests", and they match that description. They're not great. They can and should be improved.

Submit jokes with the CLI

The JokeAPI is not only capable of getting jokes, you can also create new jokes. It would be interesting if the CLI was extended to also add jokes using the submit endpoint.

In order to do this we would have to update the current CLI command, possibly by using the @click.group() decorator like this:

@click.group()
def jokes():
    ...

@jokes.command() # @jokes not @click
def get():
    ...

@jokes.command() # @jokes not @click
def add():
    ...

Steps

  • Split main method into multiple commands (jokes and add), making jokes the group command
  • Add new submit request and corresponding command
  • Add tests for submit command
  • Profit ๐Ÿฅณ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.