Skip to content

Commit

Permalink
v1.0.2 | Добавление поддержки ЕГАИС
Browse files Browse the repository at this point in the history
  • Loading branch information
li0ard committed Apr 24, 2024
1 parent 7c7f634 commit 1b12b58
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 19 deletions.
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
<img src="https://habrastorage.org/webt/7w/rw/6w/7wrw6w-k_woryibchbnbpezesag.jpeg">
<p align="center">
<img src="https://habrastorage.org/webt/7w/rw/6w/7wrw6w-k_woryibchbnbpezesag.jpeg">
</p>
<p align="center">
<img src="https://img.shields.io/pypi/v/nechestniy_znak.svg">&nbsp;&nbsp;<img src="https://img.shields.io/pypi/pyversions/nechestniy_znak.svg">
</p>

[Github](https://github.com/li0ard/nechestniy_znak)
Библеотека обертка для API ГИС МТ "Честный Знак" и API ЕГАИС

[Документация](https://li0ard.gitbook.io/nechestniy_znak/)

Библеотека обертка для API ГИС МТ "Честный Знак"
### Установка

**Требуется Python версии 3.8 или выше**
```
pip install nechestniy_znak
```

### Пример
```py
from nechestniy_znak import Lib
from nechestniy_znak import Crpt, Egais

crpt = Crpt()
print(crpt.infoFromEAN13(46494139))
print(crpt.infoFromDataMatrix("00000046209849Uon<TYfACyAJPHJ"))
print(crpt.infoFromQr("chek.markirovka.nalog.ru/kc/?kiz=RU-430302-AAA4050108"))
print(crpt.infoFromReceipt("t=20231203T2319&s=261.80&fn=7281440701309134&i=10027&fp=3516337491&n=1"))

lib = Lib()
print(lib.infoFromEAN13(46494139))
print(lib.infoFromDataMatrix("00000046209849Uon<TYfACyAJPHJ"))
print(lib.infoFromQr("chek.markirovka.nalog.ru/kc/?kiz=RU-430302-AAA4050108"))
print(lib.infoFromReceipt("t=20231203T2319&s=261.80&fn=7281440701309134&i=10027&fp=3516337491&n=1"))
egais = Egais()
print(egais.getInfoByMarkOld("22N00001543ZQO6QFMW37ZK80215021095854A4P1E4IHMW86GT5RTFHN5XXFABT9TZ9", "104-101355000854071217387105240265"))
print(egais.getInfoByMarkNew("171200031066131018001EWB6ECS6IGT6L2OH7XP6QFJMTYQMXCZ5WWVPNDLUU7BCE4FWLCBM7QDHQSESJCTOIXMEAHE2EZLXRZXJJT4UJ4OKEFEIO7RE7J7LQK2ISDFXIA34UAYOZ5ZRYFLTXI4TQ"))
print(egais.getInfoByAlcCode("0150320000003561384"))
print(egais.getChains("171200031066131018001EWB6ECS6IGT6L2OH7XP6QFJMTYQMXCZ5WWVPNDLUU7BCE4FWLCBM7QDHQSESJCTOIXMEAHE2EZLXRZXJJT4UJ4OKEFEIO7RE7J7LQK2ISDFXIA34UAYOZ5ZRYFLTXI4TQ"))
```
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "nechestniy_znak"
version = "1.0.1"
version = "1.0.2"
authors = [
{ name="li0ard", email="[email protected]" },
]
Expand All @@ -16,7 +16,7 @@ readme = "README.md"
requires-python = ">=3.8"
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
Expand Down
Empty file added src/__init__.py
Empty file.
5 changes: 4 additions & 1 deletion src/nechestniy_znak/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from .lib import *
from .crpt import *
from .egais import *

__version__ = "1.0.2"
2 changes: 1 addition & 1 deletion src/nechestniy_znak/lib.py → src/nechestniy_znak/crpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Union


class Lib:
class Crpt:
def __init__(self):
pass

Expand Down
22 changes: 22 additions & 0 deletions src/nechestniy_znak/egais.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import requests, urllib3
from typing import Union
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

class Egais:
def __init__(self):
pass

def _get(self, url: str, params: str) -> Union[list, dict]:
return requests.get(f"http://mobapi.fsrar.ru/api3/{url}?{params}", verify=False).json()

def getInfoByMarkOld(self, pdf417: str, datamatrix: str) -> Union[list, dict]:
return self._get("mark", f"DataMatrix={datamatrix}&Pdf417={pdf417}")

def getInfoByMarkNew(self, datamatrix: str) -> Union[list, dict]:
return self._get("marklong", f"Pdf417={datamatrix}")

def getInfoByAlcCode(self, alc_code: str) -> Union[list, dict]:
return self._get("product_info", f"alc_code={alc_code}")

def getChains(self, datamatrix: str) -> Union[list, dict]:
return self._get("chain", f"barcode={datamatrix}")
32 changes: 26 additions & 6 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
from nechestniy_znak import Lib
import pytest
from src.nechestniy_znak import Crpt, Egais

lib = Lib()
print(lib.infoFromEAN13(46494139))
print(lib.infoFromDataMatrix("00000046209849Uon<TYfACyAJPHJ"))
print(lib.infoFromQr("chek.markirovka.nalog.ru/kc/?kiz=RU-430302-AAA4050108"))
print(lib.infoFromReceipt("t=20231203T2319&s=261.80&fn=7281440701309134&i=10027&fp=3516337491&n=1"))
crpt = Crpt()

def test_crptEAN13():
assert crpt.infoFromEAN13(46494139)["checkResult"] == True

def test_crptDataMatrix():
assert crpt.infoFromDataMatrix("00000046209849Uon<TYfACyAJPHJ")["checkResult"] == True

def test_crptQR():
assert crpt.infoFromQr("chek.markirovka.nalog.ru/kc/?kiz=RU-430302-AAA4050108")["checkResult"] == True

def test_crptReceipt():
assert crpt.infoFromReceipt("t=20231203T2319&s=261.80&fn=7281440701309134&i=10027&fp=3516337491&n=1")["checkResult"] == True

egais = Egais()

def test_egaisMarkOld():
assert egais.getInfoByMarkOld("22N00001543ZQO6QFMW37ZK80215021095854A4P1E4IHMW86GT5RTFHN5XXFABT9TZ9", "104-101355000854071217387105240265")["success"] == True

def test_egaisMarkNew():
assert egais.getInfoByMarkNew("171200031066131018001EWB6ECS6IGT6L2OH7XP6QFJMTYQMXCZ5WWVPNDLUU7BCE4FWLCBM7QDHQSESJCTOIXMEAHE2EZLXRZXJJT4UJ4OKEFEIO7RE7J7LQK2ISDFXIA34UAYOZ5ZRYFLTXI4TQ")["success"] == True

def test_egaisChains():
assert egais.getChains("171200031066131018001EWB6ECS6IGT6L2OH7XP6QFJMTYQMXCZ5WWVPNDLUU7BCE4FWLCBM7QDHQSESJCTOIXMEAHE2EZLXRZXJJT4UJ4OKEFEIO7RE7J7LQK2ISDFXIA34UAYOZ5ZRYFLTXI4TQ")["success"] == True
Empty file added tests/__init__.py
Empty file.

0 comments on commit 1b12b58

Please sign in to comment.