Skip to content

Commit d32df71

Browse files
committed
feat: scripts: drop requests dependency
1 parent a6b56b1 commit d32df71

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

scripts/generate_problem.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env python3
22

3+
import json
34
import sys
45
import unicodedata
56
from html import parser
6-
7-
import requests
7+
from urllib import request
88

99

1010
class HTMLFilter(parser.HTMLParser):
@@ -50,8 +50,16 @@ def main() -> None:
5050
"variables": {"titleSlug": title},
5151
"query": GRAPHQL_QUERY,
5252
}
53-
r = requests.post("https://leetcode.com/graphql", json=payload)
54-
data = r.json()["data"]["question"]
53+
body = json.dumps(payload).encode()
54+
55+
headers = {
56+
"Content-Type": "application/json",
57+
"User-Agent": "Mozilla/5.0",
58+
}
59+
60+
req = request.Request("https://leetcode.com/graphql", data=body, headers=headers, method="POST")
61+
with request.urlopen(req) as resp:
62+
data = json.load(resp)["data"]["question"]
5563

5664
number = int(data["questionId"])
5765
html = str(data["content"])

0 commit comments

Comments
 (0)