-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.py
60 lines (43 loc) · 1.96 KB
/
source.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import requests,os,json
from datetime import datetime
CHAVE_API = os.environ.get('API_LOJAINTEGRADA_TOKEN')
CHAVE_APLICACAO = os.environ.get('LOJAINTEGRADA_APLICACAO_TOKEN')
API_LOJAINTEGRADA_BASE_URL = 'https://api.awsli.com.br/v1'
URL_AUTH = '&chave_api='+CHAVE_API+'&chave_aplicacao='+CHAVE_APLICACAO+''
def list_order_today():
now = datetime.today().date()
url = '/pedido/search/?since_criado='+str(now)+'&format=json'+URL_AUTH+''
try:
req = requests.get(API_LOJAINTEGRADA_BASE_URL+url)
if(req.status_code==200):
api_response = json.loads(req.text)
api_response = api_response['objects']
orders_numbers = []
for i in range(0,len(api_response),1):
if((api_response[i]['situacao']['codigo']=='pedido_efetuado') or (api_response[i]['situacao']['codigo']=='aguardando_pagamento')):
orders_numbers.append({
'ID':api_response[i]['numero']
})
return orders_numbers
except:
print('Problemas na Conexao')
def order_details(order_id):
url = '/pedido/'+str(order_id)+'/?&format=json'+URL_AUTH+''
try:
req = requests.get(API_LOJAINTEGRADA_BASE_URL+url)
if(req.status_code==200):
api_response = json.loads(req.text)
order_basic_info = []
order_basic_info.append({
'cliente':api_response['cliente']['nome'],
'envio':api_response['envios'][0]['forma_envio']['nome'],
'forma_pagamento':api_response['pagamentos'][0]['forma_pagamento']['nome'],
'forma_pagamento_icon':api_response['pagamentos'][0]['forma_pagamento']['imagem'],
'valor_total':api_response['valor_total']
})
return order_basic_info
except:
print('Problemas na Conexao')
# orders_numbers = list_order_today()
# for order_number in orders_numbers:
# print(order_details(order_number['ID']))