Skip to content

Commit 3891f56

Browse files
committed
retialer 403 fix
1 parent 91fddfe commit 3891f56

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ ujson~=5.2.0
3939
web3~=5.13.1
4040
Werkzeug~=1.0.1
4141
markupsafe==2.0.1
42-
wget==3.2
42+
urllib3==2.2.3
43+

say/crawler/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import html
33
import re
44
from typing import NamedTuple
5-
import subprocess
5+
import urllib.request
66
import json
77
import requests
88
from cachetools import TTLCache
@@ -119,16 +119,17 @@ def __init__(self, url):
119119

120120
def call_api(self, url):
121121
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}"
127128

128129
def parse_result(self, api_response):
129130
try:
130131
# Parse the JSON response
131-
json_response = json.loads(api_response)
132+
json_response = json.loads(api_response[1])
132133
return json_response
133134
except json.JSONDecodeError as e:
134135
return f"An error occurred while parsing JSON: {e}"
@@ -154,13 +155,13 @@ def get_data(self, force):
154155
api_response = self.call_api(url)
155156
parsed_result = self.parse_result(api_response)
156157
if parsed_result["status"] != 200:
157-
print("Cold not update!")
158+
print("Could not update!")
158159
return
159160
else:
160161
parsed_result = self.parse_result(api_response)
161162

162163
else:
163-
print("Cold not update!")
164+
print("Could not update!")
164165
print(url)
165166
return
166167

0 commit comments

Comments
 (0)