2
2
import urllib
3
3
import simplejson as json
4
4
import re
5
+ from yaml import load , dump
6
+ try :
7
+ from yaml import CLoader as Loader , CDumper as Dumper
8
+ except ImportError :
9
+ from yaml import Loader , Dumper
5
10
11
+ import xml .etree .ElementTree
6
12
7
13
class Jokes :
8
14
def __init__ (self ):
9
15
self .http = urllib3 .PoolManager ()
10
- print ("Sv443's JokeAPI" )
11
16
12
17
def build_request (
13
18
self ,
@@ -148,11 +153,6 @@ def send_request(self, request, response_format, return_headers, auth_token, use
148
153
except :
149
154
print (data )
150
155
raise
151
- else :
152
- data = str (data )[2 :- 1 ].replace (r'\n' , '\n ' ).replace ('\\ ' , '' )
153
- if len (' ' .join (re .split ("error" , data .lower ().replace ("\n " , "NEWLINECHAR" ))[0 :][1 :]).replace (
154
- '<' , '' ).replace ('/' , '' ).replace (' ' , '' ).replace (':' , '' ).replace ('>' , '' ).replace ('NEWLINECHAR' , '\n ' )) == 4 :
155
- return [Exception (f"API returned an error. Full response: \n \n { data } " )]
156
156
157
157
headers = str (r .headers ).replace (r'\n' , '' ).replace (
158
158
'\n ' , '' ).replace (r'\\' , '' ).replace (r"\'" , '' )[15 :- 1 ]
@@ -164,7 +164,9 @@ def send_request(self, request, response_format, return_headers, auth_token, use
164
164
if auth_token :
165
165
returns .append ({"Token-Valid" : bool (int (re .split (r"Token-Valid" , headers )[1 ][4 ]))})
166
166
167
- return returns
167
+ if len (returns ) > 1 :
168
+ return returns
169
+ return returns [0 ]
168
170
169
171
def get_joke (
170
172
self ,
0 commit comments