te25son / jokes Goto Github PK
View Code? Open in Web Editor NEWCLI app for jokes
CLI app for jokes
According the the joke api documentation, blacklisted flags should be separated by either a ,
or a +
(https://jokeapi.dev/#flags-param).
We are currently not separating them but creating multiple blacklistFlag
params. E.g. ?blacklistFlag=NSFW&blacklistFlag=EXPLICIT
This is caused by a misunderstanding of how httpx handles params.
#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%
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.
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 =
.
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.
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():
...
jokes
and add
), making jokes
the group commandA declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.