File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Expand file tree Collapse file tree 3 files changed +16
-8
lines changed File renamed without changes.
Original file line number Diff line number Diff line change
1
+ import urllib3
2
+ import urllib
3
+ import json
4
+ from jokeapi .main import Jokes
Original file line number Diff line number Diff line change 1
- import requests
1
+ import urllib3
2
2
import urllib
3
+ import json
3
4
4
5
5
6
class Jokes :
6
7
def __init__ (self ):
8
+ self .http = urllib3 .PoolManager ()
7
9
print ("Sv443's JokeAPI" )
8
10
9
11
def build_request (
@@ -57,9 +59,10 @@ def build_request(
57
59
else :
58
60
search_string = urllib .parse .quote (search_string )
59
61
if id_range :
60
- range_limit = requests .get ("https://sv443.net/jokeapi/v2/info" ).json ()[
61
- "jokes"
62
- ]["totalCount" ]
62
+
63
+ r = self .http .request ('GET' , "https://sv443.net/jokeapi/v2/info" )
64
+ range_limit = json .loads (r .data )["jokes" ]["totalCount" ]
65
+
63
66
if len (id_range ) > 2 :
64
67
raise Exception ("id_range must be no longer than 2 items." )
65
68
elif id_range [0 ] < 0 :
@@ -101,13 +104,14 @@ def build_request(
101
104
return r
102
105
103
106
def send_request (self , request , response_format ):
104
- r = requests .get (request )
107
+ r = self .http .request ('GET' , request )
108
+
105
109
if response_format == "json" :
106
- return r . json ( )
110
+ return json . loads ( r . data )
107
111
elif response_format == "xml" :
108
- return r .content
112
+ return r .data
109
113
else :
110
- return r .content
114
+ return r .data
111
115
112
116
def get_joke (
113
117
self ,
You can’t perform that action at this time.
0 commit comments