Получение чеков из ТаксКом и загрузка их в 1С по организации Maverik
This commit is contained in:
75
taxcom_maverik.py
Normal file
75
taxcom_maverik.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
import json, filecmp, shutil, requests
|
||||||
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
|
from time import sleep
|
||||||
|
from icecream import ic
|
||||||
|
|
||||||
|
ic.disable()
|
||||||
|
|
||||||
|
ID = [ ('7385440800019283','c9722276-9dce-11ef-86ff-8a456ecaea20','Хабаровск'),
|
||||||
|
('9961440300761252','34dfe5e2-9f7c-11ec-ed95-0cc47ab40806','Комсомольск_на_Амуре'),
|
||||||
|
('7385440800015768','7f8bb0cc-d7a5-11ee-85fe-8a456ecaea20','Береста 6'),
|
||||||
|
]
|
||||||
|
|
||||||
|
while True:
|
||||||
|
CurDate = datetime.date(datetime.now())
|
||||||
|
prevDate = datetime.date(datetime.now())
|
||||||
|
try:
|
||||||
|
for fn, salepoint, kassa in ID:
|
||||||
|
ic(fn, salepoint)
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Integrator-ID": "BFFFC47E-38BB-4845-8399-7C2F5AB11A3C"
|
||||||
|
}
|
||||||
|
data = {
|
||||||
|
"Login": "myasnikova@maverik.ru",
|
||||||
|
"Password": "qolabuyi"
|
||||||
|
}
|
||||||
|
result = requests.post('https://api-lk-ofd.taxcom.ru/API/v2/Login', headers=headers, data=json.dumps(data), timeout=(20, 240))
|
||||||
|
sessionToken = result.json()['sessionToken']
|
||||||
|
headers = {
|
||||||
|
"Content-Type":"application/json",
|
||||||
|
"Session-Token": f"{sessionToken}"
|
||||||
|
}
|
||||||
|
ic(result.text)
|
||||||
|
ic(sessionToken)
|
||||||
|
try:
|
||||||
|
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']:
|
||||||
|
shiftNumber = i['shiftNumber']
|
||||||
|
fnFactoryNumber = i['fnFactoryNumber']
|
||||||
|
ic(result.text)
|
||||||
|
try:
|
||||||
|
result = requests.get(f'https://api-lk-ofd.taxcom.ru/API/v2/DocumentList?fn={fn}&shift={shiftNumber}&type=3', headers=headers, timeout=(20, 240))
|
||||||
|
ic(result.text)
|
||||||
|
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=<b>Taxcom:</b>\nЧека нет')
|
||||||
|
continue
|
||||||
|
with open('check', '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):
|
||||||
|
print(f'{kassa} -- Новые чеки отсутствуют')
|
||||||
|
continue
|
||||||
|
shutil.copy('check', kassa)
|
||||||
|
Path('check').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))
|
||||||
|
print(result.text)
|
||||||
|
print('-----------------')
|
||||||
|
except:
|
||||||
|
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=<b>Taxcom:</b>\n{e}')
|
||||||
|
|
||||||
|
print('#################')
|
||||||
|
print('#################')
|
||||||
|
print('#################')
|
||||||
|
sleep(120)
|
||||||
Reference in New Issue
Block a user