Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
feat(requester): ✨ allow params in get method
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Jun 13, 2022
1 parent 3e19011 commit b85da0d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions utils/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
# 发布 CurseForgeModpackDownloader 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。

# 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看 <https://www.gnu.org/licenses/>。
from urllib.parse import quote
from urllib.parse import quote, urlencode
from urllib.request import Request, urlopen

from typing import Any, Dict


class Response:
def __init__(self, response):
Expand All @@ -34,8 +36,20 @@ class Requester:
}

@classmethod
def get(cls, url: str) -> Response:
def get(cls, url: str, params: Dict[str, Any] = None) -> Response:
"""
Request using get method.
:param url: URL.
:param params: Parametric.
:return: A Response object.
"""
url = quote(url, safe=':/')

# add params
if params:
url = url + '?' + urlencode(params)

# send request
request = Request(url, headers=cls.HEADERS, method='GET')
return Response(urlopen(request))

Expand Down

0 comments on commit b85da0d

Please sign in to comment.