added docker-compose.yaml and Dockerfile

This commit is contained in:
Sergey
2024-08-10 12:47:30 +03:00
parent 6ad5e18879
commit 48b0f23bf3
5 changed files with 262 additions and 204 deletions

View File

@@ -1,29 +1,24 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# __author__ = 'szhdanoff@gmail.com'
__version__ = '1.0.1'
__version__ = '1.0.3'
import os
import requests
import json
from dotenv import load_dotenv
load_dotenv()
# local imports
# import app
is_prod = bool(os.getenv('PRODUCTION', False))
if is_prod:
url = 'https://pos-api.dinect.com/20130701/'
else:
url = 'https://pos-api-ote.dinect.com/20130701/'
print(is_prod, url)
print('PRODUCTION:', is_prod, '| API URL:', url)
APP_TOKEN = os.getenv('APP_TOKEN')
POS_TOKEN = os.getenv('POS_TOKEN')
# APP_TOKEN = os.getenv('APP_TOKEN')
# POS_TOKEN = os.getenv('POS_TOKEN')
app_token = os.getenv('APP_TOKEN')
pos_token = os.getenv('POS_TOKEN')
@@ -42,8 +37,6 @@ HEADERS = {
}
# GET /20130701/tokens/?next=/20130701/logon
# https://pos-api.dinect.com/20130701/tokens/3b01228843d115ae8c03a4d3b20dcb545dbb228c
def get_user(search_id, get_type='auto', headers=None) -> tuple:
"""
A function to get user information based on the search_id and get_type.
@@ -118,57 +111,27 @@ def new_user(full_name, phone, gender=1, foreign_card=None, email=None, headers=
return False, r.json()
def bonuses_update(
user_id,
summ_total,
bonus_amount,
sum_with_discount,
sum_discount,
doc_id,
headers=None):
def new_user_by_card(external_card, full_name, phone, gender=1, email=None, headers=None, use_existing=True):
"""
Updates the bonuses for a user.
Creates a new user by card.
Args:
user_id (int): The ID of the user.
summ_total (float): The total amount.
bonus_amount (float): The bonus amount.
sum_with_discount (float): The amount with discount.
sum_discount (float): The discount amount.
doc_id (str): The document ID.
external_card (str): The external card code.
full_name (str): The full name of the user.
phone (str): The phone number of the user.
gender (int, optional): The gender of the user. Defaults to 1.
email (str, optional): The email of the user. Defaults to None.
headers (dict, optional): The headers to include in the request. Defaults to None.
use_existing (bool, optional): Whether to bind the user to an existing card. Defaults to True.
Returns:
tuple: A tuple containing a boolean indicating the success of the request and the JSON response.
If the request is successful, the boolean is True and the JSON response is returned.
If the request is unsuccessful, the boolean is False and the JSON response is returned.
If the request is unsuccessful, the boolean is False and the error message is returned.
"""
if headers is None:
headers = HEADERS
base_url = url + 'users/' + str(user_id) + '/purchases/'
params = {
"doc_id": doc_id,
"bonus_amount": bonus_amount,
"sum_total": summ_total,
"sum_discount": sum_discount,
"sum_with_discount ": sum_with_discount,
"commit": 'True',
"curr_iso_name": 'RUB',
"override": 'True',
# "date": '2024-08-03 12:53:07',
}
r = requests.post(base_url, headers=headers, json=params)
if r.status_code == 201:
return True, r.json()
else:
return False, r.json()
def new_user_by_card(external_card, full_name, phone, gender=1, email=None, headers=None, use_existing=True):
if headers is None:
headers = HEADERS
base_url = url + 'cards/'
params = {
'full_name': full_name,
@@ -212,46 +175,33 @@ def add_external_card(user_id, card, headers=None):
return True, r.json()
# user_date = new_user('Test2', '79039426493', email='YlEJp@example.com')
# print(user_date)
def bonuses_update(
user_id,
summ_total,
bonus_amount,
sum_with_discount,
sum_discount,
doc_id,
headers=None,
dry_run=False
):
if headers is None:
headers = HEADERS
# 79039426498
# (True, {'DIN': 232113, 'ID': '4620011139016260791309380'})
# result, user_id, user_card, purchases_url, data = get_user('1234567890123')
# result, user_id, user_card, purchases_url, data = get_user('79039426493', get_type='phone')
# print(result, data)
# if result:
# # user_id = data[0].get('id')
# # user_card = data[0].get('card')
# # purchases_url = data[0].get('purchases_url')
# print('user_id', user_id)
# print('user_card', user_card)
# print('purchases_url', purchases_url)
# добавление внешней карты лояльности
# print(get_user('4620011139016689273132009'))
# print(get_user('1234567890123'))
# print(get_user('+79039406889'))
# print(new_user())
# (True, '{"DIN":3152300,"ID":"4620011139016570939672611"}')
# print(bonuses_update(
# user_id=int('1002'),
# summ_total=100.00,
# bonus_amount=10.00,
# doc_id='test12',
# sum_with_discount=90.00,
# sum_discount=10.00,
# ))
# print(get_user('79039426493', get_type='phone'))
# (True, {'DIN': 3155239, 'ID': '4620011139016802073627661'})
# print(new_user_by_card(
# external_card='1234567891235', full_name='Test', phone='79039426495', email='123321@example.com', use_existing=False
# ))
base_url = url + 'users/' + str(user_id) + '/purchases/'
params = {
"doc_id": doc_id,
"bonus_amount": bonus_amount,
"sum_total": summ_total,
"sum_discount": sum_discount,
"sum_with_discount ": sum_with_discount,
"commit": 'True',
"curr_iso_name": 'RUB',
"override": 'True'
# "date": '2024-08-03 12:53:07',
}
r = requests.post(base_url, headers=headers, json=params)
if r.status_code == 201:
return True, r.json()
else:
return False, r.text