feat: end-point for deal document generation
This commit is contained in:
35
utils/code128.py
Normal file
35
utils/code128.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import re
|
||||
|
||||
def to_set_c(text):
|
||||
# Match pairs of digits and map them to the appropriate ASCII characters
|
||||
return ''.join([
|
||||
chr(int(ascii_code) + 100 if int(ascii_code) > 94 else int(ascii_code) + 32)
|
||||
for ascii_code in re.findall(r'\d{2}', text)
|
||||
])
|
||||
|
||||
def check_sum_128(data, start_code):
|
||||
sum_value = start_code
|
||||
for i, char in enumerate(data):
|
||||
code = ord(char)
|
||||
value = code - 100 if code > 199 else code - 32
|
||||
sum_value += (i + 1) * value
|
||||
|
||||
checksum = (sum_value % 103) + 32
|
||||
if checksum > 126:
|
||||
checksum += 68
|
||||
return chr(checksum)
|
||||
|
||||
def encode128(text, code_abc="B"):
|
||||
start_code = chr(ord(code_abc.upper()) + 138)
|
||||
stop = chr(206)
|
||||
|
||||
if code_abc.upper() == 'C':
|
||||
text = to_set_c(text)
|
||||
|
||||
check = check_sum_128(text, ord(start_code) - 100)
|
||||
|
||||
# Replace spaces with ASCII 194
|
||||
text = text.replace(" ", chr(194))
|
||||
|
||||
return start_code + text + check + stop
|
||||
|
||||
20
utils/images_fetcher.py
Normal file
20
utils/images_fetcher.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import asyncio
|
||||
import base64
|
||||
from typing import List, Tuple
|
||||
|
||||
import aiohttp
|
||||
|
||||
|
||||
async def fetch_image(url: str) -> str:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url) as response:
|
||||
if response.status == 200:
|
||||
image_data = await response.read()
|
||||
return base64.b64encode(image_data).decode("utf-8")
|
||||
else:
|
||||
return ""
|
||||
|
||||
|
||||
async def fetch_images(urls: List[str]) -> Tuple[str]:
|
||||
tasks = [fetch_image(url) for url in urls]
|
||||
return await asyncio.gather(*tasks)
|
||||
Reference in New Issue
Block a user