2
2
import html
3
3
import re
4
4
from typing import NamedTuple
5
- import subprocess
5
+ import urllib . request
6
6
import json
7
7
import requests
8
8
from cachetools import TTLCache
@@ -119,16 +119,17 @@ def __init__(self, url):
119
119
120
120
def call_api (self , url ):
121
121
try :
122
- # Run the wget command and capture the output
123
- result = subprocess .run (['wget' , '-qO-' , url ], capture_output = True , text = True , check = True )
124
- return result .stdout
125
- except subprocess .CalledProcessError as e :
126
- return f"An error occurred: { e } "
122
+ with urllib .request .urlopen (url ) as response :
123
+ status_code = response .getcode ()
124
+ content = response .read ().decode ('utf-8' )
125
+ return status_code , content
126
+ except urllib .error .URLError as e :
127
+ return None , f"An error occurred: { e } "
127
128
128
129
def parse_result (self , api_response ):
129
130
try :
130
131
# Parse the JSON response
131
- json_response = json .loads (api_response )
132
+ json_response = json .loads (api_response [ 1 ] )
132
133
return json_response
133
134
except json .JSONDecodeError as e :
134
135
return f"An error occurred while parsing JSON: { e } "
@@ -154,13 +155,13 @@ def get_data(self, force):
154
155
api_response = self .call_api (url )
155
156
parsed_result = self .parse_result (api_response )
156
157
if parsed_result ["status" ] != 200 :
157
- print ("Cold not update!" )
158
+ print ("Could not update!" )
158
159
return
159
160
else :
160
161
parsed_result = self .parse_result (api_response )
161
162
162
163
else :
163
- print ("Cold not update!" )
164
+ print ("Could not update!" )
164
165
print (url )
165
166
return
166
167
0 commit comments