From c95ea39edfca902d23457ed580a82ff25877ceb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BB=D0=B8=D0=B3=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BA=D0=BE=20=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9?= Date: Thu, 7 Aug 2025 16:21:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B8=20=D0=B2=D0=BE=D0=B7=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA=D0=BD=D0=BE=D0=B2=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BE?= =?UTF-8?q?=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D1=8F=D1=8E=D1=82=D1=81=D1=8F=20=D1=83=D0=B2=D0=B5?= =?UTF-8?q?=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20Roc?= =?UTF-8?q?ketChat.=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B8=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0=201=D0=A1?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=20=D0=BE=D1=82=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=BE=D0=B9=20=D1=87=D0=B5=D0=BA=D0=BE=D0=B2?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- taxcom_maverik.py | 76 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/taxcom_maverik.py b/taxcom_maverik.py index 6d40294..215e17a 100644 --- a/taxcom_maverik.py +++ b/taxcom_maverik.py @@ -3,12 +3,44 @@ from datetime import datetime from pathlib import Path from time import sleep from icecream import ic +from socket import create_connection + +def check_server(ip, port): + """Проверять доступность сервера""" + try: + create_connection((ip, port), timeout=2) + return True + except OSError: + return False + +def send_rocketchat_notification(text, proccess='Разобраться!'): + ROCKET_CHAT_WEBHOOK_URL = 'https://chat.maverik.ru/hooks/6881da844a6bb0ff6126fb0c/sQXCxLCrfNCtYumnWaEKbyqYvFhHSFCSevy8iBR3T2beP8j5' + data = { + "alias": "Чеки Мэверик", + "text": text, + "attachments": [ + { + "text": f"**{proccess}**", + "color": "#5B34E7" + } + ] + } + + headers = {'Content-Type': 'application/json'} + + try: + response = requests.post(ROCKET_CHAT_WEBHOOK_URL, json=data, headers=headers) + if response.status_code != 200: + print(f"Ошибка отправки уведомления: {response.text}") + except Exception as e: + print(f"Ошибка при отправке уведомления: {e}") ic.disable() ID = [ ('7385440800019283','c9722276-9dce-11ef-86ff-8a456ecaea20','Хабаровск'), - ('9961440300761252','34dfe5e2-9f7c-11ec-ed95-0cc47ab40806','Комсомольск_на_Амуре'), + ('7381440900804318','34dfe5e2-9f7c-11ec-ed95-0cc47ab40806','Комсомольск_на_Амуре'), ('7385440800015768','7f8bb0cc-d7a5-11ee-85fe-8a456ecaea20','Береста 6'), + ('7381440900865598','b0657834-65f9-11f0-8bb1-74563c59aa03','Новороссийск'), ] while True: @@ -34,8 +66,10 @@ while True: ic(result.text) ic(sessionToken) try: + n = 0 result = requests.get(f"https://api-lk-ofd.taxcom.ru/API/v2/ShiftList?fn={fn}&begin={prevDate}T00:00:00&end={CurDate}T23:59:59", headers=headers, timeout=(20, 240)) for i in result.json()['records']: + n += 1 shiftNumber = i['shiftNumber'] fnFactoryNumber = i['fnFactoryNumber'] ic(result.text) @@ -45,31 +79,45 @@ while True: cheks = result.json()['records'] except: ic() - requests.get(f'https://api.telegram.org/bot5374522720:AAGoNUYCEyJ-7-bSAQPT7aV_W2GWcinnkQU/sendMessage?parse_mode=HTML&chat_id=394151541&text=Taxcom:\nЧека нет') + # requests.get(f'https://api.telegram.org/bot5374522720:AAGoNUYCEyJ-7-bSAQPT7aV_W2GWcinnkQU/sendMessage?parse_mode=HTML&chat_id=394151541&text=Taxcom Maverik:\nЧека нет') + # send_rocketchat_notification(f'Чеков нет: {kassa}', 'Taxcom Maverik') continue - with open('check', 'w', encoding='utf-8') as f: + with open(f'check_{n}', 'w', encoding='utf-8') as f: f.write(str(cheks)) - if Path('check').is_file(): - if Path(kassa).is_file(): - if filecmp.cmp('check', kassa): + if Path(f'check_{n}').is_file(): + if Path(f'{kassa}_{n}').is_file(): + if filecmp.cmp(f'check_{n}', f'{kassa}_{n}'): print(f'{kassa} -- Новые чеки отсутствуют') continue - shutil.copy('check', kassa) - Path('check').unlink() + shutil.copy(f'check_{n}', f'{kassa}_{n}') + Path(f'check_{n}').unlink() data = {"salepoint": salepoint, "res": str(cheks)} data = json.dumps(data, ensure_ascii=False).encode('utf-8') print(kassa) - result = requests.post('http://10.15.0.3/bso_maverik/hs/exchange/saveTaxcomDocs', data=data, allow_redirects=False, auth=('robot', 's38*Cqy2L*PB'), timeout=(10, 120)) + if check_server('1c.maverik.ru', 443): + result = requests.post('https://1c.maverik.ru/bso_maverik/hs/exchange/saveTaxcomDocs', data=data, allow_redirects=False, auth=('robot', 's38*Cqy2L*PB'), timeout=(10, 120)) + elif check_server('10.15.0.3', 80): + result = requests.post('http://10.15.0.3/bso_maverik/hs/exchange/saveTaxcomDocs', data=data, allow_redirects=False, auth=('robot', 's38*Cqy2L*PB'), timeout=(10, 120)) + else: + if Path(f'{kassa}_{n}').is_file(): + Path(f'{kassa}_{n}').unlink() + print('Ошибка загрузки чеков в 1С.\nСервер не доступен!\nЗагрузка повторится позже.') + send_rocketchat_notification('Ошибка загрузки чеков в 1С.\nСервер не доступен!\nЗагрузка повторится через 1 час.', 'Taxcom Maverik') + sleep(3600) + break print(result.text) print('-----------------') - except: + except Exception as e: + # requests.get(f'https://api.telegram.org/bot5374522720:AAGoNUYCEyJ-7-bSAQPT7aV_W2GWcinnkQU/sendMessage?parse_mode=HTML&chat_id=394151541&text=Taxcom Maverik:\n{e}') + send_rocketchat_notification(e, 'Taxcom Maverik') continue print('#################') except Exception as e: - requests.get(f'https://api.telegram.org/bot5374522720:AAGoNUYCEyJ-7-bSAQPT7aV_W2GWcinnkQU/sendMessage?parse_mode=HTML&chat_id=394151541&text=Taxcom:\n{e}') + # requests.get(f'https://api.telegram.org/bot5374522720:AAGoNUYCEyJ-7-bSAQPT7aV_W2GWcinnkQU/sendMessage?parse_mode=HTML&chat_id=394151541&text=Taxcom Maverik:\n{e}') + send_rocketchat_notification(e, 'Taxcom Maverik') - print('#################') - print('#################') - print('#################') + print('continue\n\n') +# print('#################') +# print('#################') sleep(120) \ No newline at end of file