Skip to content

Commit e739ad3

Browse files
committed
PyPi compatibility and general upgrades.
1 parent 71a70e2 commit e739ad3

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

LICENSE renamed to LICENSE.txt

File renamed without changes.

jokeapi/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import urllib3
2+
import urllib
3+
import json
4+
from jokeapi.main import Jokes

JokeAPI Wrapper/main.py renamed to jokeapi/main.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import requests
1+
import urllib3
22
import urllib
3+
import json
34

45

56
class Jokes:
67
def __init__(self):
8+
self.http = urllib3.PoolManager()
79
print("Sv443's JokeAPI")
810

911
def build_request(
@@ -57,9 +59,10 @@ def build_request(
5759
else:
5860
search_string = urllib.parse.quote(search_string)
5961
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+
6366
if len(id_range) > 2:
6467
raise Exception("id_range must be no longer than 2 items.")
6568
elif id_range[0] < 0:
@@ -101,13 +104,14 @@ def build_request(
101104
return r
102105

103106
def send_request(self, request, response_format):
104-
r = requests.get(request)
107+
r = self.http.request('GET', request)
108+
105109
if response_format == "json":
106-
return r.json()
110+
return json.loads(r.data)
107111
elif response_format == "xml":
108-
return r.content
112+
return r.data
109113
else:
110-
return r.content
114+
return r.data
111115

112116
def get_joke(
113117
self,

0 commit comments

Comments
 (0)