Пример #1
0
 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()
Пример #2
0
    def init_etsy(self):
        logging.info('Getting keys...')
        key_file = os.path.join(self.data, 'keys.txt')
        keys = self.get_api_key(key_file)
        more_keys = self.oAuthHelper(keys['key'], keys['shared_secret'])
        keys.update(more_keys)

        logging.info('Creating API object...')
        etsy_oauth = EtsyOAuthClient(
            client_key=keys['key'],
            client_secret=keys['shared_secret'],
            resource_owner_key=keys['oauth_token'],
            resource_owner_secret=keys['oauth_secret'])
        etsy = Etsy(etsy_oauth_client=etsy_oauth)
        return etsy
Пример #3
0
#[fulo] Scraping Data from API to Google Sheets for client 

import requests
import gspread
from etsy2 import Etsy
import json
from gspread_dataframe import get_as_dataframe, set_with_dataframe
from gspread_formatting.dataframe import format_with_dataframe
import pandas as pd
# import schedule
# import time

#key allowing access to etsy api
etsy = Etsy(api_key= 'j8mpgzb24pbhd5z1hax579mo')

#data from api to df and filtering columns that are necassary
listedItems = etsy.findAllListingActive()
etsyListed = pd.DataFrame(listedItems)
df1 = etsyListed[['title', 'taxonomy_path', 'price', 'currency_code', 'quantity', 'views', 'num_favorers', 'materials']]

TrendingItems = etsy.getTrendingListings()
etsyTrending = pd.DataFrame(TrendingItems)
df2 = etsyTrending[['title', 'taxonomy_path', 'price', 'currency_code', 'quantity', 'views', 'num_favorers', 'materials']]

CurrentFeaturedItems = etsy.findAllCurrentFeaturedListings()
etsyFeatured = pd.DataFrame(CurrentFeaturedItems)
df3 = etsyFeatured[['title', 'taxonomy_path', 'price', 'currency_code', 'quantity', 'views', 'num_favorers', 'materials']]

#changing name of columns in df
df1.columns = ['Title', 'Categories', 'Price', 'Currency', 'Quantity Available', 'Views', 'No. of Favourites', 'Materials Used']
df2.columns = ['Title', 'Categories', 'Price', 'Currency', 'Quantity Available', 'Views', 'No. of Favourites', 'Materials Used']
Пример #4
0
 def __init__(self, api_key=''):
     self.conn = Etsy(api_key=api_key)
     self.limit = 25
Пример #5
0
class EtsyController():
    """ Controller class for talking to the Etsy API. Will return useful results based off of need """
    def __init__(self, api_key=''):
        self.conn = Etsy(api_key=api_key)
        self.limit = 25

    def get_products_keywords(self, keywords=''):
        # Get product name, description, tags, and URL
        results = self.conn.findAllListingActive(keywords=keywords,
                                                 limit=self.limit,
                                                 includes="Images")

        #print(results[0].keys())
        needed_elems = [
            'title', 'description', 'price', 'url', 'views', 'listing_id',
            'Images'
        ]
        for i in range(0, len(results)):
            results[i] = dict(
                filter(lambda elem: elem[0] in needed_elems,
                       results[i].items()))
            try:
                results[i]['Images'] = results[i]['Images'][0]['url_170x135']
            except IndexError as e:
                print(results[i]['Images'])
        return results

    def get_products_tags(self, tags=[]):

        results = self.conn.findAllListingActive(tags=tags, limit=self.limit)
        needed_elems = ['title', 'description', 'price', 'url']

        for i in range(0, len(results)):
            results[i] = dict(
                filter(lambda elem: elem[0] in needed_elems, results[i]))
        return results

    def get_products_images(self, pids=[]):
        results = []
        results = list(
            map(lambda pid: self.conn.getImage_Listing(listing_id=pid), pids))
        return results

    def get_product_id(self, pid=''):
        results = self.conn.getListing(listing_id=pid)
        results = json.loads(results)
        return results

    def get_url(self, pid=''):
        result = self.conn.getListing(listing_id=pid)
        return result[0][
            'url'] if result and result[0]['state'] == 'active' else ''

    def get_current_price(self, pid):
        """ Grab current price of an item from Etsy by using its listing id """
        needed_elems = ['title', 'price', 'url', 'listing_id']
        results = self.conn.getListing(listing_id=pid)

        if results[0]['state'] != 'active':
            return None
        else:
            return {'price': results[0]['price']}
Пример #6
0
        oauth_consumer_secret=config.oauth_consumer_secret,
        etsy_env=etsy_env)
else:
    sys.stderr.write('ERROR: You must set oauth_consumer_key and oauth_consumer_secret in config.py\n')
    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...")
#
Пример #7
0
# Define the list of rooms (useful to retrieve the ID of the rooms, knowing their name)
rooms_list = {}
rooms = app.client.conversations_list()
for room in rooms["channels"]:
    rooms_list[room["id"]] = room["name"]
    rooms_list[room["name"]] = room["id"]

# Now that we have an understanding of what channels are available and what the actual
# IDs are, we can't send a message to a named channel anymore (e.g. "bottest") -- it's
# gotta go to the internal Slack channel ID. So now we'll redefine DEFAULT_CHANNEL to
# be the internal slack ID version.
DEFAULT_CHANNEL = rooms_list[DEFAULT_CHANNEL]

# Define the mod to ping for periodic_callback (leave to None if no mod has to be pinged)
mods_array: List = []
for i in range(0, 24):
    mods_array.append(None)

# Import PluginManager from here
PluginManager = PM(COMMAND_PREFIXES, BEGINNING_COMMAND_PREFIXES)

mpl.rcParams["figure.figsize"] = [20, 10]

etsy = Etsy(etsy_oauth_client=EtsyOAuthClient(
    client_key=os.environ.get('etsy_key'),
    client_secret=os.environ.get('etsy_secret'),
    resource_owner_key=os.environ.get('etsy_oauth_token'),
    resource_owner_secret=os.environ.get('etsy_oauth_token_secret')))

TIME_STARTED = datetime.now()
Пример #8
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