From 9d30b480ad1dcf07ef8389fea8755bfbb52d355d Mon Sep 17 00:00:00 2001 From: ZeN Date: Fri, 7 Jul 2023 16:20:20 +0300 Subject: [PATCH 1/4] fix non-ASCII symbols in search URL --- README.md | 2 +- config.example.ini | 2 +- src/config/parser.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b44b099..065f77c 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ level = 20 format = [%%(levelname)s] %%(asctime)s - %%(name)s - %%(message)s ``` `level` - Уровень логирования.
-`format` - Формат логов. (Из-за особенностей файла .ini символ '%' нужно экранировать) +`format` - Формат логов. # Как его запустить? diff --git a/config.example.ini b/config.example.ini index 64d15b8..4f29871 100644 --- a/config.example.ini +++ b/config.example.ini @@ -9,4 +9,4 @@ id = 1 [logging] level = 20 -format = [%%(levelname)s] %%(asctime)s - %%(name)s - %%(message)s +format = [%(levelname)s] %(asctime)s - %(name)s - %(message)s diff --git a/src/config/parser.py b/src/config/parser.py index 7aa4a79..7c51a6d 100644 --- a/src/config/parser.py +++ b/src/config/parser.py @@ -1,4 +1,4 @@ -from configparser import ConfigParser +from configparser import ConfigParser, ExtendedInterpolation from dataclasses import dataclass from typing import List @@ -32,7 +32,7 @@ class Config: @classmethod def load_config(cls, filename: str) -> "Config": - raw_config = ConfigParser() + raw_config = ConfigParser(interpolation=ExtendedInterpolation()) raw_config.read(filename, encoding="utf-8") if not raw_config.sections(): raise FileNotFoundError(f"File {filename} is not defined") From d89f6df75bbb5127ee1925a5b901175994b935a8 Mon Sep 17 00:00:00 2001 From: ZeN Date: Fri, 7 Jul 2023 16:30:04 +0300 Subject: [PATCH 2/4] fix regexp --- src/market/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/market/api.py b/src/market/api.py index c799eb9..0f90f19 100644 --- a/src/market/api.py +++ b/src/market/api.py @@ -11,7 +11,7 @@ def search(self, category: str, search_params: str) -> dict: def parse_search_data(search_url: str) -> Optional[Tuple[str, str]]: - parse = re.search(r"https://lzt.market/([\w\-]+)/(.+)", search_url) + parse = re.search(r"https://lzt.market/([\w\-]+)/\?(.+)", search_url) if not parse: raise TypeError("Format search URL is invalid") category, search_params = parse.groups() From f6efcbdf3843e0ce95192514eb1e839a61d13406 Mon Sep 17 00:00:00 2001 From: ZeN Date: Fri, 7 Jul 2023 16:30:22 +0300 Subject: [PATCH 3/4] fix presentation non-ASCII symbols --- src/__main__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/__main__.py b/src/__main__.py index 852083b..d6d30af 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -1,4 +1,5 @@ import logging +import urllib.parse from src.config import Config from src.market import MarketAPI, MarketBuyError, MarketItem @@ -38,7 +39,7 @@ def main(): logging.info( "По запросу %s с параметрами %s найдено %s аккаунтов", search, - params, + urllib.parse.unquote(params), len(items), ) From ac722ee53fff7772a76aaae0904d704260d4c5d9 Mon Sep 17 00:00:00 2001 From: ZeN Date: Fri, 7 Jul 2023 16:33:59 +0300 Subject: [PATCH 4/4] disable ssl in requests to `api.telegram.org` --- src/telegram/api.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/telegram/api.py b/src/telegram/api.py index 3b45116..c831f31 100644 --- a/src/telegram/api.py +++ b/src/telegram/api.py @@ -1,4 +1,5 @@ import json +import ssl from typing import Optional from urllib import parse, request @@ -25,7 +26,8 @@ def api_request( data=request_data, method=request_method, ) - with request.urlopen(api_request) as response_object: + context = _get_disable_ssl() + with request.urlopen(api_request, context=context) as response_object: response = json.load(response_object) return response @@ -35,3 +37,10 @@ def send_message(self, text: str, chat_id: int, **kwargs) -> dict: {"text": text, "chat_id": chat_id, **kwargs}, ) return response + + +def _get_disable_ssl() -> ssl.SSLContext: + context = ssl.create_default_context() + context.check_hostname = False + context.verify_mode = ssl.CERT_NONE + return context