Retrieving food data with Amazon API (Python)

Overview

Get food data using Amazon api (python).

Step 1: Get the Amazon API available

Learn how to use Amazon API to some extent. Reference URL http://www.ajaxtower.jp/ecs/

Step 2: Timestamp

Add a time stamp to the query. The format is as follows

import time
Time = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
url_qs.append(("Timestamp", [Time]))
url_qs = sorted(url_qs)

Step 3: Signature generation

First, a hash is generated according to the sha-256 standard using the private key given by amazon.

import hmac, hashlib
hmac_digest = hmac.new(array['secret_key'], req, hashlib.sha256).digest()

Encode the generated hash into base64 and quote to complete the sinature

import base64
base64_encoded = base64.b64encode(hmac_digest) # base64
signature = urllib2.quote(base64_encoded)

Step 4: Parse and extract xml

from pyquery import PyQuery as pq
from lxml import etree

a = pq(etree.fromstring(test), parser='xml')
        f = a('ns|Feature', namespaces={"ns":"http://webservices.amazon.com/AWSECommerceService/2011-08-01"}).text())

Raw materials are stored in Feature

Recommended Posts

Retrieving food data with Amazon API (Python)
Data analysis with python 2
Data analysis with Python
Get stock price data with Quandl API [Python]
Sample data created with python
Use Trello API with python
Use Twitter API with Python
Get Youtube data with python
Web API with Python + Falcon
Play RocketChat with API / Python
Call the API with python3.
Use subsonic API with python3
Read json data with python
Get data from analytics API with Google API Client for python
Play with YouTube Data API v3 using Google API Python Client
Create Awaitable with Python / C API
Data acquisition using python googlemap api
Get reviews with python googlemap api
Run Rotrics DexArm with python API
Quine Post with Qiita API (Python)
[Python] Get economic data with DataReader
Hit the Etherpad-lite API with Python
Python data structures learned with chemoinformatics
[python] Read information with Redmine API
Get Amazon data using Keep API # 1 Get data
Easy data visualization with Python seaborn.
Process Pubmed .xml data with python
Data analysis starting with python (data visualization 1)
Data analysis starting with python (data visualization 2)
Python application: Data cleansing # 2: Data cleansing with DataFrame
Subtitle data created with Amazon Transcribe
Collecting information from Twitter with Python (Twitter API)
Get additional data in LDAP with python
Data pipeline construction with Python and Luigi
Receive textual data from mysql with python
Building a Python3 environment with Amazon Linux2
Automatically create Python API documentation with Sphinx
[Note] Get data from PostgreSQL with Python
Process Pubmed .xml data with python [Part 2]
Simple Slack API client made with Python
Add a Python data source with Redash
Python: Reading JSON data from web API
Try working with binary data in Python
Generate Japanese test data with Python faker
Use Amazon Simple Notification Service with Python
Convert Excel data to JSON with python
[Python] Use string data with scikit-learn SVM
Download Japanese stock price data with python
Get Google Fit API data in Python
Manipulate DynamoDB data with Lambda (Node & Python)
Send data to DRF API with Vue.js
Convert FX 1-minute data to 5-minute data with Python
Get Youtube data in Python using Youtube Data API
[Python] Quickly create an API with Flask
Recommendation of Altair! Data visualization with Python
Data analysis starting with python (data preprocessing-machine learning)
Let's do MySQL data manipulation with Python
Organize data divided by folder with Python
Serverless face recognition API made with Python
Send an email with Amazon SES + Python
[Python] Get Python package information with PyPI API