From 0256f1435a9860a838c70ae52abce112d6e08b31 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:20:58 +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_ip.py | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/taxcom_ip.py b/taxcom_ip.py index 1a1ca85..a617976 100644 --- a/taxcom_ip.py +++ b/taxcom_ip.py @@ -14,6 +14,28 @@ def check_server(ip, port): 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": 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}") ID = [ ('7381440900800903','030c75c2-2f29-11eb-119f-0cc47ab40806','Волгоград_Энгельса'), @@ -51,8 +73,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) @@ -62,17 +86,17 @@ 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Чека нет') 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') @@ -82,18 +106,21 @@ while True: 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(kassa).is_file(): - Path(kassa).unlink() + if Path(f'{kassa}_{n}').is_file(): + Path(f'{kassa}_{n}').unlink() print('Ошибка загрузки чеков в 1С.\nСервер не доступен!\nЗагрузка повторится позже.') + send_rocketchat_notification('Ошибка загрузки чеков в 1С.', 'Сервер 1С не доступен!\nПроверить нужно OVPN.\nЗагрузка повторится через 1 час.') sleep(3600) break print(result.text) print('-----------------') - except: + except Exception as e: + send_rocketchat_notification('Ошибка чеков по ИП.', str(e)) 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:\n{e}') + send_rocketchat_notification('Ошибка чеков по ИП.', str(e)) print('#################') print('#################')