Not getting amazon SalesRank using amazon API - python

I was using ItemLookup to get SalesRank using Amazon Product API. I am using python amazon product api
import amazonproduct
from lxml import objectify
config = {
'access_key': 'access key',
'secret_key': 'secret key',
'associate_tag': 'associate tag',
'locale': 'us'
}
amazon = amazonproduct.API(cfg=config)
result = amazon.item_lookup('B01B83IWH0', ResponseGroup="SalesRank")
but when i print the results their is no SalesRank, has amazon stopped giving SalesRank?
AttributeError: no such child: {http://webservices.amazon.com/AWSECommerceService/2011-08-01}SalesRank
I tried using amazon scratchpad but it also didn't give SalesRank but they have mention in their documentation to get SalesRank. How do I get SalesRank or if their is any alternative(I tried web scraping but amazon blocks me frequently). Please help, I am a beginner in using API's.

Using this library:
https://pypi.python.org/pypi/python-amazon-simple-product-api
from amazon.api import AmazonAPI
api = AmazonAPI(ACCESS_KEY, ACCESS_KEY_SECRET, amazon_tag)
item= api.item_lookup('B01B83IWH0')
# Get Sales Rank
rank = item.sales_rank
This gets rank, but doesn't seem to reflect the current rank listed on Amazon's website. I'm only just familiarizing myself with the Amazon API, will update with elaboration and details.

Related

how to modify multiple woocommerce products with python

I hope all you guys be fine.
I was trying to modify multiple products in Woocommerce with python(Restful Api WooCommerce)
here is the code I used:
import sys
import json
from woocommerce import API
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
wcapi = API(
url="https://...",
consumer_key="ck_...",
consumer_secret="cs_...",
wp_api = True,
version="wc/v3",
query_string_auth=True # Force Basic Authentication as query string true and using under HTTPS
)
data = {"id":"1995","regular_price":"1775000","sale_price":"1685000","stock_quantity":"6"},
{"id":"4673","regular_price":"2300000","sale_price":"2045000","stock_quantity":"15"}
print(wcapi.put("products/bulk",data).json())
but when I run the code, I got below error:
{'code': 'rest_no_route', 'message': 'No route was found matching the URL and request method', 'data': {'status': 404}}
product IDs are available.
before trying to make some changes on bulk, I was able to modify a single product with the below code:
print(wcapi.put("products/1995",data).json())
my current Woocommerce version 3.9 - & - current python version 3.8.1
i was not able to find the solution or why is that happening. how to fix it?
also how can i modify multiple variable Woocommerce products?
Thanks
finally, the problem got solved.
I just wanted to post it here for the future use of others who may face such this problem.
here is the change which I made in the code:
data = {
"update":
[
{
"id":"1995",
"regular_price":"1775000",
"sale_price":"1685000",
"stock_quantity":"6"},
{
"id":"4673",
"regular_price":"2300000",
"sale_price":"2045000",
"stock_quantity":"15"}
]
}
# Bulk edit of Woocommerce products - here we have 2 sample products
print(wcapi.put("products/batch",data).json())
if you have a better way or think should notice any other thing for working with woocommerce in python, happy to have your post below in this post:-)

My Google-Places API Key is activated but not working

I'm using this package to run Google Places API on Python. I'm running the following code:
from googleplaces import GooglePlaces, types, lang
key='XXXXXXX'
google_places = GooglePlaces(key)
query_result = google_places.nearby_search(
location='London, England', keyword='Fish and Chips',
radius=20000, types=[types.TYPE_FOOD])
print(query_result)
However when I do that, I get this error:
{
"error_message" : "This API project is not authorized to use this API. Please ensure this API is activated in the Google Developers Console: https://console.developers.google.com/apis/api/geocoding_backend?project=_",
"results" : [],
"status" : "REQUEST_DENIED"
}
However my API is enabled and everything seems cool, as you can see below:
Can someone help here?

gdata autentication trouble python

I ran for awhile a python script to post articles on my blogspot blog.
everything ran smoothly until I started to get this auth error
RequestError: {'status': 401, 'body': 'User does not have permission to create new post', 'reason': 'Unauthorized'}
I really can't understand how to fix it reading gdata documentation.
Could you please suggest me how to do?
Thank you
Here the part of my code that doesn't work anymore:
from gdata import service
import gdata
import atom
blogger_service = service.GDataService('xxxxxx','xxxxxx')
blogger_service.service = 'blogger'
blogger_service.account_type = 'GOOGLE'
blogger_service.server = 'www.blogger.com'
blogger_service.ProgrammaticLogin()
def CreatePublicPost(blogger_service, blog_id, title, content,tags):
entry = gdata.GDataEntry()
entry.title = atom.Title('xhtml', title)
entry.content = atom.Content(content_type='html', text=content)
for tag in tags :
category = atom.Category(term=tag, scheme="http://www.blogger.com/atom/ns#")
entry.category.append(category)
return blogger_service.Post(entry, '/feeds/%s/posts/default' % blog_id)
Now there is a API version 3.0...
This old version is obsolete and no longer works, apparently...
You can find more about it here:
https://developers.google.com/blogger/
https://developers.google.com/blogger/docs/3.0/using/
And if you have questions about authentication, maybe those links help:
Having trouble trying to use gdata and oauth2 in python
Authentication with the Google Docs List API, Python and OAuth 2

Accessing ISI Web of Science through SOAP

I'm trying to write a python script that retrieves information about publications from ISI Web of Science. I found domoritz's python script wos.py on GitHub. It uses Suds to connect to the ISI Web of Science web service. I've imported it into my python script and I tried this code, following the very brief instructions in the comments:
from wos import *
soap = WokmwsSoapClient()
results = soap.search('Hallam')
I then get an error:
suds.WebFault: Server raised fault: 'line 1:1: unexpected token: Hallam'
I looked through the code in wos.py. Here is the search function:
def search(self, query):
qparams = {
'databaseID' : 'WOS',
'userQuery' : query,
'queryLanguage' : 'en',
'editions' : [{
'collection' : 'WOS',
'edition' : 'SCI',
},{
'collection' : 'WOS',
'edition' : 'SSCI',
}]
}
rparams = {
'count' : 5, # 1-100
'firstRecord' : 1,
'fields' : [{
'name' : 'Relevance',
'sort' : 'D',
}],
}
return self.client['search'].service.search(qparams, rparams)
I thought maybe query can't be just a plain python string, as I saw in the WSDL page that userQuery is actually of type xs:string. But this page says that userQuery "Must be a valid WOKQL query statement. This requirement is enforced internally", which makes it seem like I don't have to pass in a special type. Anyway, I tried appending 'xs:string' to the beginning of query but I got the same error.
Does anybody know the proper way to use this method?
You could try to use the Wos Python Client that can be install with:
pip install wos
And then you can use it like this:
from wos import WosClient
import wos.utils
with WosClient('JohnDoe', '12345') as client:
print(wos.utils.query(client, 'AU=Knuth Donald'))
You will also have a CLI tool to be used like:
wos -u 'JohnDoe' -p '12345' query 'AU=Knuth Donald'
*DISCLAIMER: I don't work for Web of Science but I am the author of the client. You need to have web services access (which is a paid service in addition to the normal WOS access) since Web of Science does not allow web services requests coming from normal users. You should ask your university to provide you with the username and password that WOS gave them. This is not just for my client but for anything that uses WOS web service. *
So apparently passing in a python string was fine, but I needed a string that was more like a search query. I found this example on the website I mentioned before:
<soap:Body>
<woksearch:search xmlns:woksearch="http://woksearch.v3.wokmws.thomsonreuters.com">
<!-- this request has the minimum required elements,
but contains all valid retrieve options
for this operation and databaseId -->
<queryParameters>
<databaseId>WOK</databaseId>
<userQuery>AU=Arce, G*</userQuery>
<queryLanguage>en</queryLanguage>
</queryParameters>
....
So I tried using results = soap.search('AU=Hallam') and that worked. I can now do things like print results.recordsFound and I get correct answers.

Trouble with Twitter API using Python

I'm having some trouble in this python code:
import twitter
twitter_search = twitter.Twitter(domain="search.twitter.com")
trends = twitter_search.trends()
The error (404 page not found) is right here:
I'm using this package: http://github.com/sixohsix/twitter
Because of the new API change, you need to use this program:
import twitter
twitter_api = twitter.Twitter(domain="api.twitter.com", api_version='1')
WORLD_WOE_ID = 1
world_trends = twitter_api.trends._(WORLD_WOE_ID)
trends = world_trends()
print [trend['name'] for trend in trends[0]['trends']]
This is based, in part, on the book errata website.
According to the Twitter API documentation for the trends call the domain should be api.twitter.com:
import twitter
twitter_search = twitter.Twitter(domain="api.twitter.com")
print twitter_search.trends()
{u'trends': [{u'url': u'http://search.twitter.com/search?q=%23weedcommandments',
u'name': u'#weedcommandments'}, ...
You may want to checkout the updated IPython Notebook for Chapter 1 of Mining the Social Web that shows an updated example for this workflow and API call as well as a little bit of other context that is compatible with Twitter's v1.1 API. See http://nbviewer.ipython.org/urls/raw.github.com/ptwobrussell/Mining-the-Social-Web/master/ipython_notebooks/Chapter1.ipynb for a read-only version of the notebook.

Categories