Skip to content

Instantly share code, notes, and snippets.

@allanbatista
Last active March 30, 2021 12:15
Show Gist options
  • Save allanbatista/b798ed1100ff8e620a6fa9f1a7910357 to your computer and use it in GitHub Desktop.
Save allanbatista/b798ed1100ff8e620a6fa9f1a7910357 to your computer and use it in GitHub Desktop.
Mercado Livre (MELI) - Download Categoria e Atributos
import json
import requests
from tqdm import tqdm
categories = requests.get("https://api.mercadolibre.com/sites/MLB/categories/all").json()
def get_attributes(cat):
cat['attributes'] = requests.get(f'https://api.mercadolibre.com/categories/{cat["id"]}/attributes').json()
for subcat in cat.get('children_categories', []):
get_attributes(subcat)
for key, cat in tqdm(list(categories.items()), total=len(categories)):
get_attributes(cat)
with open("meli-categories-with-attributes.jsonl", "w+") as f:
for cat in categories.values():
f.write(json.dumps(cat)+"\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment