Use gilt-python to access the Gilt API to obtain sale and product data on live and upcoming sales.
Use pip to install:
$ pip install gilt
You can fall back to ye olde way of installing (but pip is awesomer) by downloading the latest source (ZIP) and then run:
$ python setup.py install
You may need to run the above commands with
Access to the Gilt API needs an API key, which you can get for free. Once you have it, it needs to be passed to the GiltRestClient constructor or passed as an environment variable:
from gilt import GiltRestClient apikey = "ACXXXXXXXXXXXXXXXXX" client = GiltRestClient(apikey)
The better, more secure way is to set GILT_API_KEY in your environment, then construct your client like:
from gilt import GiltRestClient client = GiltRestClient()
Retrieve a list of all live sales
from datetime import datetime from gilt.rest import GiltRestClient from gilt.util import sort_by_ending_soonest client = GiltRestClient() sales = client.sales.active.list() sales.sort(sales, sort_by_ending_soonest) now = datetime.now() for sale in client.sales.active.list(): print "%(name)s: %(description)s" % sale.__dict__ if now > sale.begins: print " Begins in %s and finishes in %s" % (now - sale.begins, sale.ends - now) else: print " Began %s ago and finishes in %s" % (sale.begins - now, sale.ends - now)
Retrieve upcoming sales in the womens store
from gilt.rest import GiltRestClient client = GiltRestClient() sales = client.sales.upcoming.list('women') for sale in client.sales.active.list(): print "%s, %s: %d products" % (sale.name, sale.description, len(sale.products))
Get details on a product in a sale
The below will print details on all products in the first active sale in the kids store.
from gilt.rest import GiltRestClient client = GiltRestClient() sale = client.sales.active.list('kids') products = client.products.details.list(sale.products) for i, product in enumerate(products): print " %3d. %s by %s" % (, product.name, product.brand) for sku in product.skus print " %s on sale for $%1.2f" % (sku.description, sku.sale_price)
Model classes should be pythonic.
Users should not have to use dictionaries to access fields. Types should be what you expect, including dates.
Loading data should be pythonic.
Throwing together big and small programs should use familiar constructs with minimal magic.
Respect and reflect the API
Naming is kept as consistent as possible with exactly what the API provides. This includes methods, classes and fields.
Everything is in UTC. It is recommended that you work with UTC except for display formatting.