diff --git a/README.md b/README.md index f0e76bf..52be033 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Downloads](https://pepy.tech/badge/jokeapi)](https://pepy.tech/project/jokeapi) [![Downloads](https://pepy.tech/badge/jokeapi/month)](https://pepy.tech/project/jokeapi/month) [![Downloads](https://pepy.tech/badge/jokeapi/week)](https://pepy.tech/project/jokeapi/week) -[![CircleCI](https://circleci.com/gh/thenamesweretakenalready/Sv443s-JokeAPI-Python-Wrapper.svg?style=svg)](https://circleci.com/gh/thenamesweretakenalready/Sv443s-JokeAPI-Python-Wrapper) +[![CircleCI](https://circleci.com/gh/leet-hakker/JokeAPI-Python.svg?style=svg)](https://circleci.com/gh/benjhar/JokeAPI-Python) @@ -42,15 +42,19 @@ Note that joke submissions are manually checked and you will be ratelimited. ### Example ```python - from jokeapi import Jokes # Import the Jokes class - - j = Jokes() # Initialise the class - joke = j.get_joke()[0] # Retrieve a random joke - if joke["type"] == "single": # Print the joke - print(joke["joke"]) - else: - print(joke["setup"]) - print(joke["delivery"]) +from jokeapi import Jokes # Import the Jokes class +import asyncio + +async def print_joke(): + j = await Jokes() # Initialise the class + joke = await j.get_joke() # Retrieve a random joke + if joke["type"] == "single": # Print the joke + print(joke["joke"]) + else: + print(joke["setup"]) + print(joke["delivery"]) + +asyncio.run(print_joke()) ``` ### Parameters @@ -71,7 +75,7 @@ If left blank it will default to use `Any`. ##### Example ```python - joke = j.get_joke(category=['programming', 'dark']) # Will return a joke that fits in either the programming or dark category. + joke = await j.get_joke(category=['programming', 'dark']) # Will return a joke that fits in either the programming or dark category. ``` --- @@ -91,7 +95,7 @@ If left blank it will default to `None`. ##### Example ```python - joke = j.get_joke(blacklist=['nsfw', 'racist']) # Will return a joke that does not have either the flag "nsfw" or "racist". + joke = await j.get_joke(blacklist=['nsfw', 'racist']) # Will return a joke that does not have either the flag "nsfw" or "racist". ``` --- @@ -110,7 +114,7 @@ If left blank it will default to `json`. ##### Example ```python - joke = j.get_joke(response_format="xml") # Will return a joke in xml format. + joke = await j.get_joke(response_format="xml") # Will return a joke in xml format. ``` --- @@ -128,7 +132,7 @@ If left blank it will default to `Any` ##### Example ```python - joke = j.get_joke(joke_type="twopart") # Will return a twopart joke; both a setup and a delivery. + joke = await j.get_joke(joke_type="twopart") # Will return a twopart joke; both a setup and a delivery. ``` --- @@ -142,7 +146,7 @@ If left blank it will default to `None` ##### Example ```python - joke = j.get_joke(search_string="the") # Will return a joke with the word "the" in it. + joke = await j.get_joke(search_string="the") # Will return a joke with the word "the" in it. # If there are no jokes then it will return the error from the API. ``` @@ -160,7 +164,7 @@ If left blank it will default to the maximum range. ##### Example ```python - joke = j.get_joke(id_range=[10,100]) # Will return a joke with the ID between 10 and 100. + joke = await j.get_joke(id_range=[10,100]) # Will return a joke with the ID between 10 and 100. ``` --- @@ -174,7 +178,7 @@ api defaults to 1 if you use a number larger than the maximum. Defaults to 1. ##### Example ```python - joke = j.get_joke(amount=2) # Will return 2 jokes. + joke = await j.get_joke(amount=2) # Will return 2 jokes. ``` --- @@ -187,7 +191,7 @@ documentation. Defaults to en. ##### Example ```python - joke = j.get_joke(lang="de") + joke = await j.get_joke(lang="de") ``` --- @@ -201,7 +205,7 @@ more requests than normal users. Defaults to None ##### Example ```python - joke = j.get_joke(auth_token="aaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbb") # Will send the token to the api in a header. + joke = await j.get_joke(auth_token="aaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbb") # Will send the token to the api in a header. ``` --- @@ -216,7 +220,7 @@ to change it ##### Example ```python - joke = j.get_joke(user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0") + joke = await j.get_joke(user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0") # This is in fact the default user agent, and tells the API that we are visitng the page from a Firefox 77.0 # browser using Windows 10 64bit. ``` @@ -233,7 +237,7 @@ Defaults to False. ##### Example ```python - response = j.get_joke(return_headers=True) + response = await j.get_joke(return_headers=True) joke = response[0] headers = response[1] @@ -340,16 +344,20 @@ If not, feel free to ask me through one of the channels provided below. ```python from jokeapi import Jokes +import asyncio -j = Jokes() +async def submit_new_joke(): + j = await Jokes() -j.submit_joke("Miscellaneous", "funny haha", { - "nsfw": False, - "religious": False, - "political": False, - "racist": False, - "sexist": False -}, lang="de") + await j.submit_joke("Miscellaneous", "funny haha", { + "nsfw": False, + "religious": False, + "political": False, + "racist": False, + "sexist": False + }, lang="de") + +asyncio.run(submit_new_joke()) ``` --- @@ -417,8 +425,6 @@ Defaults to `en` ![Discord](https://discord.com/assets/07dca80a102d4149e9736d4b162cff6f.ico)[**Discord**](https://discord.gg/mB989eP) -[Issue Tracker](https://github.com/thenamesweretakenalready/Sv443s-JokeAPI-Python-Wrapper/issues) +[Issue Tracker](https://github.com/thenamesweretakenalready/JokeAPI-Python/issues) [e-mail](mailto:leet_haker@cyber-wizard.com) - -[Twitter](https://twitter.com/HakkerLeet) diff --git a/pyproject.toml b/pyproject.toml index df3da86..872d72b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,16 @@ [tool.poetry] name = "jokeapi" -version = "1.0.0" +version = "1.0.5" description = "Python API Wrapper for Sv443's JokeAPI (https://v2.jokeapi.dev)" -authors = ["thenamesweretakenalready <43702423+thenamesweretakenalready@users.noreply.github.com>"] -license = "GPL v3.0" +readme = "README.md" +homepage = "https://pypi.org/project/jokeapi" +repository = "https://github.com/leet-hakker/JokeAPI-Python" +authors = ["leet-hakker "] +maintainers = ["leet-hakker"] +license = "GPL-3.0-only" [tool.poetry.dependencies] -python = "^3.9" +python = "^3.7" urllib3 = "^1.26.2" aiohttp = "^3.7.4" simplejson = "^3.17.2" @@ -18,7 +22,6 @@ black = "^21.6b0" pytest = "^6.2.4" pytest-asyncio = "^0.15.1" - [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" diff --git a/src/jokeapi/__init__.py b/src/jokeapi/__init__.py index 89c9276..06dc843 100644 --- a/src/jokeapi/__init__.py +++ b/src/jokeapi/__init__.py @@ -1,3 +1 @@ from jokeapi.main import Jokes - -print("Sv443's JokeAPI") diff --git a/src/jokeapi/main.py b/src/jokeapi/main.py index f972651..7fc2031 100644 --- a/src/jokeapi/main.py +++ b/src/jokeapi/main.py @@ -157,7 +157,7 @@ async def build_request( if search_string: r += f"&contains={search_string}" if id_range: - r += f"i&dRange={id_range[0]}-{id_range[1]}" + r += f"&idRange={id_range[0]}-{id_range[1]}" if amount > 10: raise ValueError( f"amount parameter must be no greater than 10. you passed {amount}." @@ -230,8 +230,6 @@ async def send_request( returns.append(headers) if auth_token: - print(len(headers.split("token-valid"))) - print(len(headers.split("Token-Valid"))) if "token-valid" in headers: returns.append( {"Token-Valid": bool(int(headers.split("token-valid")[1][4]))}