Skip to content

Commit

Permalink
refactor(src): change repo name
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-pony committed Nov 8, 2023
1 parent a4e9ff4 commit c8ca21b
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 8 deletions.
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[tool.poetry]
name = "scrapy-kit"
version = "0.1.12"
name = "spider-tool-kit"
version = "0.1.0"
description = ""
authors = ["Pony.Ma <[email protected]>"]
readme = "README.md"
packages = [{include = "scrapy_kit"}]
homepage = "https://scrapy-kit.readthedocs.io/en/latest/"
documentation = "https://scrapy-kit.readthedocs.io/en/latest/"
repository = "https://github.com/ma-pony/scrapy-kit"
packages = [{include = "spider_tool_kit"}]
homepage = "https://spider-tool-kit.readthedocs.io/en/latest/"
documentation = "https://spider-tool-kit.readthedocs.io/en/latest/"
repository = "https://github.com/ma-pony/spider-tool-kit"
license = "Apache-2.0"
keywords = ["scrapy", "scrapy-kit", "scrapy-kit"]
keywords = ["spider", "scrapy", "scrapy-kit", "spider-kit", "spider-tools", "spider-tool-kit"]


[tool.poetry.dependencies]
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions spider_tool_kit/contants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENCODINGS = ['latin1', 'cp1252', 'iso-8859-1', 'gbk', 'ascii']
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions spider_tool_kit/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .text_encode import *
16 changes: 16 additions & 0 deletions spider_tool_kit/tools/text_encode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from spider_tool_kit.contants import ENCODINGS


def fix_encode(garbled_text: str, decoding='utf-8') -> (str, str):
"""
修复乱码
:param garbled_text: 乱码文本
:param decoding: 解码方式
:return: 正常文本, 编码
"""
for encoding in ENCODINGS:
try:
res = garbled_text.encode(encoding).decode(decoding)
return res, encoding
except (UnicodeEncodeError, UnicodeDecodeError):
continue
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from pytest_twisted import ensureDeferred

from scrapy_kit.pipelines.mongo_pipeline import MongoPipeline
from spider_tool_kit.scrapy.pipelines.mongo_pipeline import MongoPipeline


class TestMongoPipeline:
Expand Down
Empty file.
Empty file.
Empty file added test/unit/tools/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions test/unit/tools/text_encode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from spider_tool_kit.tools import fix_encode


class TestTextEncode:
def test_fix_encode(self):
garbled_text = "亿元"
expected_text = "亿元"
expected_encoding = "cp1252"
result = fix_encode(garbled_text)
assert result == (expected_text, expected_encoding)

0 comments on commit c8ca21b

Please sign in to comment.