Пример #1
0
    sys.exit(1)

if hasattr(config, 'oauth_token_key') and hasattr(config, 'oauth_token_secret'):
    oauth_client.token = oauth.Token(
        key=config.oauth_token_key,
        secret=config.oauth_token_secret)
else:
    webbrowser.open(oauth_client.get_signin_url())
    oauth_client.set_oauth_verifier(input('Enter OAuth verifier: '))
    write_config_file(oauth_client.token)

etsy_api = Etsy(etsy_oauth_client=oauth_client, etsy_env=etsy_env, log=my_log)

# print 'oauth access token: (key=%r; secret=%r)' % (oauth_client.token.key, oauth_client.token.secret)

print('findAllShopListingsActive => %r' % etsy_api.findAllShopListingsActive(shop_id=config.user_id, sort_on='created', limit=1))

# print('getListing => %r' % etsy_api.getListing(listing_id=63067548))

print('findAllUserShippingTemplates => %r' % etsy_api.findAllUserShippingTemplates(user_id=config.user_id))

# TODO write UPDATE/INSERT test that doesnt cost money
# TODO write test that excerises boolean param types

#def testCreateListing():
#    print("Creating listing...")
#
#    result = etsy_api.createListing(
#        description=config.description,
#        title=config.title,
#        price=config.price,
Пример #2
0
class EtsyAPI(BasePlatformAPI):
    persistent_identifier = "etsy"
    webhook_enabled = False

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        etsyAuthToken = ProtectedResource.objects(name="etsyAuthToken").first()
        etsyAuthSecret = ProtectedResource.objects(
            name="etsyAuthSecret").first()
        if etsyAuthToken is None or etsyAuthSecret is None:
            loginURL, temp_oauth_token_secret = EtsyOAuthHelper.get_request_url_and_token_secret(
                consumer_key, consumer_secret, requiredPermissions)
            temp_oauth_token = parse_qs(
                urlparse(loginURL).query).get("oauth_token").pop()
            productDBLogger.warn(
                "Etsy is not authenticated!!! Visit this URL and input the verification code to authenticate!"
            )
            productDBLogger.warn(loginURL)
            productDBLogger.warn(temp_oauth_token)
            productDBLogger.warn(temp_oauth_token_secret)
            verificationCode = input("Verification Code> ")
            oauth_token, oauth_token_secret = EtsyOAuthHelper.get_oauth_token_via_verifier(
                consumer_key, consumer_secret, temp_oauth_token,
                temp_oauth_token_secret, verificationCode)
            etsyAuthToken = ProtectedResource(name="etsyAuthToken",
                                              value=oauth_token)
            etsyAuthSecret = ProtectedResource(name="etsyAuthSecret",
                                               value=oauth_token_secret)
            etsyAuthToken.save()
            etsyAuthSecret.save()
        etsyOAuthClient = EtsyOAuthClient(
            client_key=consumer_key,
            client_secret=consumer_secret,
            resource_owner_key=etsyAuthToken.value,
            resource_owner_secret=etsyAuthSecret.value)
        self.EtsyClient = Etsy(etsy_oauth_client=etsyOAuthClient)
        newEtsyListing = models.EtsyParityRecord(listingType="foo",
                                                 listingID="738914494",
                                                 productID="3779581207")
        print(newEtsyListing.getRawListingProductsJSON(self.EtsyClient))
        print(newEtsyListing.pushQuantityToEtsy(10, self.EtsyClient))
        # print(self._getListing("738914494"))
        exit()

    def getAllStockCounts(self):
        pass

    def _bulkFetchListings(self):
        finishedReading = False
        totalAmountOfResourcesFetched = 0
        page = 1
        limit = 100
        fetchedResourceJSONList = list()
        while not finishedReading:
            responseJSON = self.EtsyClient.findAllShopListingsActive(
                shop_id=shop_id, limit=limit, page=page)
            totalAmountOfResourcesOnEtsy = self.EtsyClient.count
            totalAmountOfResourcesFetched += len(responseJSON)
            fetchedResourceJSONList = fetchedResourceJSONList + responseJSON
            if totalAmountOfResourcesOnEtsy == totalAmountOfResourcesFetched:
                finishedReading = True
            else:
                page += 1
                finishedReading = False
        return fetchedResourceJSONList

    def _getListing(self, listing_id):
        responseJSON = self.EtsyClient.getListing(listing_id=listing_id)
        return responseJSON