Exemple #1
0
class TestEtsyAPI(object):
    """Tests the Etsy API client"""

    def setup(self):
        """
        For each test, create an esty api connection
        """
        self.etsy_api = EtsyAPI(os.environ["ETSY_API_KEY"])

    def test_get_shops(self):
        resp = self.etsy_api.get_shops(keyword="gifts", limit=50)
        assert len(resp['results']) == 50

    def test_get_shop_listings(self):
        resp = self.etsy_api.get_shops(keyword="gifts", limit=1)
        shop_id = resp['results'][0]['shop_id']
        resp = self.etsy_api.get_shop_listings(shop_id)

        assert resp
Exemple #2
0
def get_top_terms(keyword=None, pool_size=10, shop_limit=50):
    """Get the 5 most popular terms from listing for a set of etsy shops"""
    etsy_api = EtsyAPI(os.environ["ETSY_API_KEY"])
    resp = etsy_api.get_shops(keyword=keyword, limit=shop_limit)
    shops = resp["results"]

    if pool_size:
        # We use gevent to execute each shop task in pararell
        # Due to Etsy's API rate limiting, it'll only be very useful
        # if most shops have less than 100 items
        p = pool.Pool(pool_size)
        min_request_duration = pool_size * 0.1
        for shop in shops:
            p.apply_async(
                get_shop_top_terms,
                args=[shop, etsy_api],
                kwds=dict(min_request_duration=min_request_duration))
        p.join()
    else:
        for shop in shops:
            get_shop_top_terms(shop, etsy_api, term_limit=5)
Exemple #3
0
 def setup(self):
     """
     For each test, create an esty api connection
     """
     self.etsy_api = EtsyAPI(os.environ["ETSY_API_KEY"])