@@ -42,15 +42,19 @@ Note that joke submissions are manually checked and you will be ratelimited.
42
42
### Example
43
43
44
44
``` python
45
- from jokeapi import Jokes # Import the Jokes class
46
-
47
- j = Jokes() # Initialise the class
48
- joke = j.get_joke()[0 ] # Retrieve a random joke
49
- if joke[" type" ] == " single" : # Print the joke
50
- print (joke[" joke" ])
51
- else :
52
- print (joke[" setup" ])
53
- print (joke[" delivery" ])
45
+ from jokeapi import Jokes # Import the Jokes class
46
+ import asyncio
47
+
48
+ async def print_joke ():
49
+ j = await Jokes() # Initialise the class
50
+ await j.get_joke() # Retrieve a random joke
51
+ if joke[" type" ] == " single" : # Print the joke
52
+ print (joke[" joke" ])
53
+ else :
54
+ print (joke[" setup" ])
55
+ print (joke[" delivery" ])
56
+
57
+ asyncio.run(print_joke())
54
58
```
55
59
56
60
### Parameters
@@ -71,7 +75,7 @@ If left blank it will default to use `Any`.
71
75
##### Example
72
76
73
77
``` python
74
- joke = j.get_joke(category = [' programming' , ' dark' ]) # Will return a joke that fits in either the programming or dark category.
78
+ joke = await j.get_joke(category = [' programming' , ' dark' ]) # Will return a joke that fits in either the programming or dark category.
75
79
```
76
80
77
81
---
@@ -91,7 +95,7 @@ If left blank it will default to `None`.
91
95
##### Example
92
96
93
97
``` python
94
- joke = j.get_joke(blacklist = [' nsfw' , ' racist' ]) # Will return a joke that does not have either the flag "nsfw" or "racist".
98
+ joke = await j.get_joke(blacklist = [' nsfw' , ' racist' ]) # Will return a joke that does not have either the flag "nsfw" or "racist".
95
99
```
96
100
97
101
---
@@ -110,7 +114,7 @@ If left blank it will default to `json`.
110
114
##### Example
111
115
112
116
``` python
113
- joke = j.get_joke(response_format = " xml" ) # Will return a joke in xml format.
117
+ joke = await j.get_joke(response_format = " xml" ) # Will return a joke in xml format.
114
118
```
115
119
116
120
---
@@ -128,7 +132,7 @@ If left blank it will default to `Any`
128
132
##### Example
129
133
130
134
``` python
131
- joke = j.get_joke(joke_type = " twopart" ) # Will return a twopart joke; both a setup and a delivery.
135
+ joke = await j.get_joke(joke_type = " twopart" ) # Will return a twopart joke; both a setup and a delivery.
132
136
```
133
137
134
138
---
@@ -142,7 +146,7 @@ If left blank it will default to `None`
142
146
##### Example
143
147
144
148
``` python
145
- joke = j.get_joke(search_string = " the" ) # Will return a joke with the word "the" in it.
149
+ joke = await j.get_joke(search_string = " the" ) # Will return a joke with the word "the" in it.
146
150
# If there are no jokes then it will return the error from the API.
147
151
```
148
152
@@ -160,7 +164,7 @@ If left blank it will default to the maximum range.
160
164
##### Example
161
165
162
166
``` python
163
- joke = j.get_joke(id_range = [10 ,100 ]) # Will return a joke with the ID between 10 and 100.
167
+ joke = await j.get_joke(id_range = [10 ,100 ]) # Will return a joke with the ID between 10 and 100.
164
168
```
165
169
166
170
---
@@ -174,7 +178,7 @@ api defaults to 1 if you use a number larger than the maximum. Defaults to 1.
174
178
##### Example
175
179
176
180
``` python
177
- joke = j.get_joke(amount = 2 ) # Will return 2 jokes.
181
+ joke = await j.get_joke(amount = 2 ) # Will return 2 jokes.
178
182
```
179
183
180
184
---
@@ -187,7 +191,7 @@ documentation. Defaults to en.
187
191
##### Example
188
192
189
193
``` python
190
- joke = j.get_joke(lang = " de" )
194
+ joke = await j.get_joke(lang = " de" )
191
195
```
192
196
193
197
---
@@ -201,7 +205,7 @@ more requests than normal users. Defaults to None
201
205
##### Example
202
206
203
207
``` python
204
- joke = j.get_joke(auth_token = " aaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbb" ) # Will send the token to the api in a header.
208
+ joke = await j.get_joke(auth_token = " aaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbb" ) # Will send the token to the api in a header.
205
209
```
206
210
207
211
---
@@ -216,7 +220,7 @@ to change it
216
220
##### Example
217
221
218
222
``` python
219
- joke = j.get_joke(user_agent = " Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0" )
223
+ joke = await j.get_joke(user_agent = " Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0" )
220
224
# This is in fact the default user agent, and tells the API that we are visitng the page from a Firefox 77.0
221
225
# browser using Windows 10 64bit.
222
226
```
@@ -233,7 +237,7 @@ Defaults to False.
233
237
##### Example
234
238
235
239
``` python
236
- response = j.get_joke(return_headers = True )
240
+ response = await j.get_joke(return_headers = True )
237
241
joke = response[0 ]
238
242
headers = response[1 ]
239
243
@@ -340,16 +344,20 @@ If not, feel free to ask me through one of the channels provided below.
340
344
341
345
``` python
342
346
from jokeapi import Jokes
347
+ import asyncio
343
348
344
- j = Jokes()
349
+ async def submit_new_joke ():
350
+ j = await Jokes()
345
351
346
- j.submit_joke(" Miscellaneous" , " funny haha" , {
347
- " nsfw" : False ,
348
- " religious" : False ,
349
- " political" : False ,
350
- " racist" : False ,
351
- " sexist" : False
352
- }, lang = " de" )
352
+ await j.submit_joke(" Miscellaneous" , " funny haha" , {
353
+ " nsfw" : False ,
354
+ " religious" : False ,
355
+ " political" : False ,
356
+ " racist" : False ,
357
+ " sexist" : False
358
+ }, lang = " de" )
359
+
360
+ asyncio.run(submit_new_joke())
353
361
```
354
362
355
363
---
@@ -417,8 +425,6 @@ Defaults to `en`
417
425
418
426
![ Discord] ( https://discord.com/assets/07dca80a102d4149e9736d4b162cff6f.ico ) [ ** Discord** ] ( https://discord.gg/mB989eP )
419
427
420
- [ Issue Tracker] ( https://github.com/thenamesweretakenalready/Sv443s- JokeAPI-Python-Wrapper /issues )
428
+ [ Issue Tracker] ( https://github.com/thenamesweretakenalready/JokeAPI-Python/issues )
421
429
422
430
[ e-mail
] ( mailto:[email protected] )
423
-
424
- [ Twitter] ( https://twitter.com/HakkerLeet )
0 commit comments