示例#1
0
def get_resource(resource_str):
    # Enter a context with an instance of the API client
    with meli.ApiClient() as api_client:
        # Create an instance of the API class
        api_instance = meli.RestClientApi(api_client)
        resource = resource_str  # A resource example like items, search, category, etc.
        access_token = ml.ACCESS_TOKEN  # Your access token.

    try:
        # Resource path GET
        print(resource)
        api_response = api_instance.resource_get(resource, access_token)
        results = api_response["results"]
        pprint(results)
    except ApiException as e:
        print("Exception when calling RestClientApi->resource_get: %s\n" % e)
示例#2
0
    def get_resource(self, resource):
        # Enter a context with an instance of the API client
        if self.access_token is None:
            raise Exception("Access token has not been generated ")

        with meli.ApiClient() as api_client:
            # Create an instance of the API class
            api_instance = meli.RestClientApi(api_client)
            access_token = self.access_token  # Your access token.
        try:
            # Resource path GET
            api_response = api_instance.resource_get(resource, access_token)
            results = api_response
            return results
        except ApiException as e:
            print("Exception when calling RestClientApi->resource_get: %s\n" % e)
示例#3
0
 def get_category_top_sellers(self, category):
     # Enter a context with an instance of the API client
     with meli.ApiClient() as api_client:
         # Create an instance of the API class
         api_instance = meli.RestClientApi(api_client)
         resource = f"sites/MLA/search?category={category}"
         sellers = {}
         try:
             sellers = self.get_full_list(api_instance, resource, 0,
                                          **{"sellers": {}})
         except ApiException as e:
             print(
                 "Exception when calling RestClientApi->resource_post: %s\n"
                 % e)
     # Order the dict descending by sold units and take the top 10
     sellers = dict(
         sorted(sellers.items(), key=lambda item: item[1], reverse=True))
     return take(10, sellers.items())
示例#4
0
 def get_category_top_prices(self, category):
     # Enter a context with an instance of the API client
     with meli.ApiClient() as api_client:
         # Create an instance of the API class
         api_instance = meli.RestClientApi(api_client)
         resource = f"sites/MLA/search?category={category}&sort=price_desc&limit=10"
         prices = {}
         try:
             api_response = api_instance.resource_get(resource, "")
         except ApiException as e:
             print(
                 "Exception when calling RestClientApi->resource_post: %s\n"
                 % e)
         for result in api_response["results"]:
             prices[result["title"]] = {
                 "price": result["price"],
                 "link": result["permalink"],
             }
     return prices
示例#5
0
# You need use this example code in to the main folder
from __future__ import print_function
import time
import meli
from meli.rest import ApiException
from pprint import pprint
from get_access_token import *
# Defining the host is optional and defaults to https://api.mercadolibre.com
# See configuration.py for a list of all supported configuration parameters.
configuration = meli.Configuration(host="https://api.mercadolibre.com")

# Enter a context with an instance of the API client
with meli.ApiClient() as api_client:
    # Create an instance of the API class
    api_instance = meli.RestClientApi(api_client)
    resource = 'users/me?access_token='  # A resource example like items, search, category, etc.
    access_token = token  # Your access token.

try:
    # Resource path GET
    api_response = api_instance.resource_get(resource, access_token)
    #pprint(api_response["nickname"])
    print("Nickname: " + str(api_response["nickname"]))
except ApiException as e:
    print("Exception when calling RestClientApi->resource_get: %s\n" % e)
示例#6
0
 def __init__(self):
     with meli.ApiClient() as api_client:
         self.api_instance = meli.RestClientApi(api_client)