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
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()
#[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']
def __init__(self, api_key=''): self.conn = Etsy(api_key=api_key) self.limit = 25
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...") #
# 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()