olá a todos, tenho o seguinte codigo escrito em python que retorna uma tabela de informações aparti dessa api de um sistema que utilizo na web varejofacil Docs , segue o código:
import os
from time import sleep
from turtle import left
import requests
import datetime
import pandas as pd
import sys
import subprocess
import pkg_resources
os.system('cls' if os.name == 'nt' else 'clear')
required = {'requests', 'pandas', 'openpyxl'}
installed = {pkg.key for pkg in pkg_resources.working_set}
missing = required - installed
if missing:
print('Instalando dependências...')
python = sys.executable
subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL)
def tolog(line):
try:
l = open('custos.log', 'r')
except:
open('custos.log', 'w')
l = open('custos.log', 'r')
log = l.readlines()
date = datetime.datetime.now().strftime('%c')
log.append('[' + date + '] ' + line + '\n')
l = open('custos.log', 'w')
l.writelines(log)
l.close()
username = 'xxx'
password = 'xxx'
while username == '' and password == '':
#username = input('\nUsername: ')
#password = input('Password: ')
if username == '' or password == '':
os.system('cls' if os.name == 'nt' else 'clear')
print('\nUsername e Password não podem ficar em branco.')
os.system('cls' if os.name == 'nt' else 'clear')
url = 'https://grupofreguesia.varejofacil.com'
userObj = {
'username': username,
'password': password
}
try:
response = requests.post(url + '/api/auth', json=userObj)
except:
print('Erro de autenticação!')
else:
if response.status_code != 200:
print('Erro de autenticação!')
tolog('Erro de autenticação! ' + str(response.status_code))
else:
token = response.json()
headers = {'Authorization': token['accessToken']}
items = []
try:
os.system('cls' if os.name == 'nt' else 'clear')
print('\nAguarde...')
api='/produto/custos'
size='500'
response = requests.get(url + '/api/v1'+api+'?start=0&count='+size, headers=headers)
total = int(response.json()['total'])
items = response.json()['items']
start = 500
while len(items) < total:
try:
os.system('cls' if os.name == 'nt' else 'clear')
print('\nAguarde...\n' + str(len(items)) + '/' + str(total))
response = requests.get(url + '/api/v1'+api+'?start=' + str(start) + '&count='+size, headers=headers)
items = items + response.json()['items']
start = start + size
except:
print('Erro ao solicitar custos!')
tolog('Erro ao solicitar custos! ' + str(response.status_code) + ' items: ' + str(len(items)))
except:
print('Erro ao solicitar custos!')
tolog('Erro ao solicitar custos! 000')
os.system('cls' if os.name == 'nt' else 'clear')
print('\nGerando planilha, aguarde...\nPode demorar alguns minutos.')
custos = pd.DataFrame.from_records(items)
nome=api.removeprefix('/').replace('/','_')
custos.to_excel('C:\PEDIDO\\'+nome+'.xlsx')
print('\n Gerado com sucesso!')
como ficaria em java esse mesmo código?