Created
April 21, 2020 12:18
-
-
Save sergiolucero/f3c29e5b266634a9aeb5393105a45e7f to your computer and use it in GitHub Desktop.
API Mercado Público
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import os | |
#ticket = os.getenv('TOKEN_MP') | |
from creds import ticket | |
WAIT = 2; # segundos entre una y otra solicitud | |
def get_OC(oc): | |
BASE_MP = 'http://api.mercadopublico.cl/servicios/v1/publico/' | |
url = f'{BASE_MP}/ordenesdecompra.json?codigo={oc}&ticket={ticket}' | |
js = requests.get(url).json()['Listado'] | |
return js | |
def get_detalle(df): | |
pdf = pd.DataFrame() | |
for oc in df.Codigo: | |
print(oc, end=',') | |
c0 = pd.DataFrame(get_OC(oc)) | |
pdf = pdf.append(c0) | |
time.sleep(WAIT) # necesario, con WAIT=1 se cae | |
print(chr(10)+str(len(pdf))) | |
return pdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment