@@ -10,8 +10,6 @@ while also maintaining a readable codebase.
10
10
11
11
You can install jokeapi through [ pip] ( https://pypi.org/project/pip/ ) by using ` pip install jokeapi `
12
12
13
- So far there are no build from source instructions.
14
-
15
13
---
16
14
17
15
# get_joke
@@ -29,7 +27,8 @@ interact with one function. This function is `get_joke()`
29
27
from jokeapi import Jokes # Import the Jokes class
30
28
31
29
j = Jokes() # Initialise the class
32
- j.get_joke() # Retrieve a random joke
30
+ joke = j.get_joke(type = " single" , response_format = " txt" ) # Retrieve a random joke
31
+ print (joke)
33
32
```
34
33
35
34
### Parameters
@@ -129,15 +128,66 @@ If left blank it will default to `None`
129
128
130
129
The range in which the selected joke should fall. ID's are decided by the order in which jokes are submitted.
131
130
The argument passes should be in form of list or tuple, and should not exceed length of 2 items. First item
132
- should be minimum 0.
131
+ should be minimum 0. Maximum value can be determined [ here ] ( https://sv443.net/jokeapi/v2/info )
133
132
134
133
If left blank it will default to the maximum range.
135
134
136
135
137
136
#### Example
138
137
139
138
``` python
140
- joke = get_joke(id_range = [10 ,100 ]) # Will return a joke with the ID between 10 and 100
139
+ joke = get_joke(id_range = [10 ,100 ]) # Will return a joke with the ID between 10 and 100.
140
+ ```
141
+
142
+ ---
143
+
144
+ ### auth_token
145
+
146
+ A string token provided by the api owner. Using it will mean you are whitelisted by the api and can make
147
+ more requests than normal users. Defaults to None
148
+
149
+
150
+ #### Example
151
+
152
+ ``` python
153
+ joke = get_joke(auth_token = " aaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbb" ) # Will send the token to the api in a header.
154
+ ```
155
+
156
+ ---
157
+
158
+ ### user_agent
159
+
160
+ A string sent the the api that tells the api what browser you are (pretending to be). The default user agent
161
+ is Mozilla Firefox from Windows 10 and should work fine, but the functionality is provided in case you wish
162
+ to change it
163
+
164
+
165
+ #### Example
166
+
167
+ ``` python
168
+ joke = get_joke(user_agent = " Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0" )
169
+ # This is in fact the default user agent, and tells the API that we are visitng the page from a Firefox 77.0
170
+ # browser using Windows 10 64bit.
171
+ ```
172
+
173
+ ---
174
+
175
+ ### return_headers
176
+
177
+ A boolean value (True or False) that tells the wrapper if you wish to receive headers in the return from the function.
178
+ Defaults to False.
179
+
180
+
181
+ #### Example
182
+
183
+ ``` python
184
+ response = get_joke(return_headers = True )
185
+ joke = response[0 ]
186
+ headers = response[1 ]
187
+ # The function returns the joke and then the headers using the "return x, y" syntax, so you can index it like a list or tuple.
188
+
189
+ print (f " Joke: { joke} " )
190
+ print (f " Headers: { headers} " )
141
191
```
142
192
143
193
---
@@ -237,7 +287,7 @@ If not, feel free to ask me through one of the channels provided below.
237
287
238
288
Developer contact:
239
289
240
- [ Discord] ( https://discord.gg/mB989eP )
290
+ ! [ Discord] ( https://discord.com/assets/07dca80a102d4149e9736d4b162cff6f.ico ) [ ** Discord ** ] ( https://discord.gg/mB989eP )
241
291
242
292
[ Issue Tracker] ( https://github.com/thenamesweretakenalready/Sv443s-JokeAPI-Python-Wrapper/issues )
243
293
0 commit comments