I tried to make a product price comparison tool of Amazon around the world with Java, Amazon Product Advertising API, Currency API (2017/01/29)

hello world!


Nice to meet you, my name is alpacatom. I am an M1 go apprentice. At last, I have a little time beyond the climax of the dissertation, so I will post it for the first time at the expense of precious Saturdays and Sundays. As a newcomer, please watch over warmly. We would appreciate it if you could give us suggestions for improvement and opinions. This time, I created a tool to compare the prices of products on Amazon in 6 countries using the Amazon Product Advertising API and Currency API. Of course, shipping is included.

Note: Be prepared for it, as it can be quite a hassle to get ready for use.

Motivation (ice break)

"I want a Blu-ray disc of everyone's favorite" Big Bang Theory "" → "But (graduate students) don't have money" → "That !? Amazon in the US is cheaper than Japan?" ← Now here I didn't really understand the result, and I knew that the price on Amazon was different for each country, so I made it.

Tips: __ Big Bang Theory What is __? A super interesting overseas comedy drama. This work can be recommended for both those who are aiming to be researchers and those who are not, especially for graduate students, it is a must-see __. By the way, I had two weeks until Season 1-6. (Netflix is the best!)

Later on, I'm thinking about buying a _Superdry _ bag ... and so on.

Reference: Superdry

Currency API Will begin the main subject. It is an API for obtaining exchange rate information, and you can use it by registering. This time I'm using the Free one. https://currencylayer.com/ Now get the API key for the Currency layer.

Amazon Product Advertising API I referred to the following article.

Amazon Associate Tag

This is a crucial moment. Register the country you want to compare and get the Associate tag. (This time it is based in Japan, so Japan is essential.) According to an article on StackOverflow, it was posted that it can not be used unless you register in each country, so register in the required country "all".

AWS access key and secret key

--Get the access key and secret key while reading the explanation on the above site. I tried various things, but for some reason it didn't work unless I separated the Japanese key (rather, it works with only two), so I got two, Japan and the others. You are now ready.

How to use

Since it was developed in Eclipse, if you are using Eclipse, import the project pulled from Github (https://github.com/alpacatom/ComparingPrices-via-AmazonAPI) and use the key obtained above (Currency.java). And SearchAnItem.java), you can use it. The search has some required parameters. --ASIN number (reference https://www.amazon.com/gp/help/customer/display.html?nodeId=200202190#find_asins) --Weight (kg) (The default is 1kg or less because the shipping charges from overseas vary depending on the weight) --The genre of the item you are looking for (eg Books, DVD, etc. For details, refer to the first column of ShipmentCharge-*. Txt.) will become necessary.

main class

Only the main function is listed below. The flow is to pull the shipping table from the CSV file and hit the Currency API and Amazon API to get the exchange rate and the price of the product information. For more information, visit Github (https://github.com/alpacatom/ComparingPrices-via-AmazonAPI)


	public static void main(String[] args) {
		// Initializing
		ItemData arr[] = new ItemData[ItemData.COUNTRY_NUM];
		for(int i=0;i<ItemData.COUNTRY_NUM;i++){
			arr[i] = new ItemData();
		String line[] = new String[ShipmentCharge.CSV_MAX_LINE_SIZE];
		ShipmentCharge SC[][] = new ShipmentCharge[ItemData.COUNTRY_NUM][ShipmentCharge.CSV_MAX_LINE_SIZE];
		// Get Shipment Charges
		for(int j=0;j<ItemData.COUNTRY_NUM;j++){
			line = ItemData.ReadFile(ShipmentCharge.ShipmentTXT[j]);
			String stmp[] = new String[ShipmentCharge.CSV_MAX_COLUM_SIZE];
			int k=0;
				stmp = MyParser.parseCSV(line[k]);
				SC[j][k] = ShipmentCharge.MakeTable(SC[j][k], stmp, j);
		// Calculate the lowest Shipment Charges each countires.
		Double[] dtmp = new Double[6];
		dtmp = ShipmentCharge.LowestCalcSC(SC,ItemData.category);
		// Get Currencies via currencylayer
        String json = Currency.GetCurrencies();
        Double CurrenciesRate[] = new Double[ItemData.COUNTRY_NUM];
        CurrenciesRate = MyParser.getCurrencies(json);
		// Get Price and Country via Amazon Product API
		String xml[] = new String[ItemData.COUNTRY_NUM];
		final String tag[] = {"CurrencyCode","FormattedPrice"};

		for(int i=0;i<ItemData.COUNTRY_NUM;i++){
			xml[i] = SearchAnItem.SearchByID(ItemData.getItemID(), i);
			arr[i].setPrice( MyParser.Convert2Double(MyParser.getTagElmFromXML(xml[i],tag[1])));

Execution result

The result of the calculation is displayed in USD dollars. So the lower TOTAL: is, the more "cheap" it is. Below is the BD price (including shipping) for The Big Bang Theory Season 1-9. As you can see, if you don't need Japanese (with English subtitles), you will get 115 * (Max-min) = 2990 yen. ad1b905491ba78d3da57cbb32752f150.png


Thank you for reading this far, and I will post it if I make something again.

What I got

--How to use Eclipse (this was my first time) --Java coding (I have never used it outside of lectures) --Touched various APIs and external libraries (how to send HTTP requests, extract elements from JSON and XML, etc.) --How to use regular expressions (dirty but I made it myself for the first time)

What i lost

--Saturday and Sunday (important here)

What I left behind

--I don't do much debugging and exception handling. (In rare cases, is it moss when sending an HTTP request? I want to fix it if I have time.) -To accommodate orders for multiple items. This time, we are only assuming single item orders, and the calculation for multiple orders will change. --Allow the ASIN number to be pulled from the URL. It is troublesome to find the ASIN number one by one. -Make it possible to select the shipping fee for express mail. There may be a demand to choose a place where cospa is good between time and money ――The base country (currently Japan) should also be selectable. If the shipping regulations change, I will have to start over. (I probably won't do it because it's a hassle to find out the price.)


Amazon Product API document http://docs.aws.amazon.com/AWSECommerceService/latest/DG/Welcome.html Currencylayer API document https://currencylayer.com/documentation File input / output https://www.caveofprogramming.com/java/java-file-reading-and-writing-files-in-java.html Regular expressions https://docs.oracle.com/javase/jp/6/api/java/util/regex/Pattern.html http://qiita.com/ymsr5612/items/7c8811b5cf37d700adc4 Base64 encoding / decoding (I was addicted to not being able to import the jar into Eclipse here) http://criticalbreak5.seesaa.net/article/420080828.html XML via DOM (not used after all) http://www.fireproject.jp/feature/xml/programing/java-dom.html JSON http://www.task-notes.com/entry/20150919/1442639772

Recommended Posts

I tried to make a product price comparison tool of Amazon around the world with Java, Amazon Product Advertising API, Currency API (2017/01/29)
I tried to make a client of RESAS-API in Java
[Java] I tried to make a maze by the digging method ♪
I tried to make a Web API that connects to DB with Quarkus
I tried to make Basic authentication with Java
A story that I wanted to write a process equivalent to a while statement with the Stream API of Java8
I tried to break a block with java (1)
I tried to make a program that searches for the target class from the process that is overloaded with Java
I tried to make a login function in Java
[Java] I tried to implement Yahoo API product search
I tried to check the operation of http request (Put) with Talented API Tester
I tried to create a java8 development environment with Chocolatey
I tried to summarize the basics of kotlin and java
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
I tried upgrading from CentOS 6.5 to CentOS 7 with the upgrade tool
I tried to make the sample application into a microservice according to the idea of the book "Microservice Architecture".
[Java] I tried to make a rock-paper-scissors game that beginners can run on the console.
[VBA] I tried to make a tool to convert the primitive type of Entity class generated by Hibernate Tools to the corresponding reference type.
I tried to solve the problem of "multi-stage selection" with Ruby
[Rails] Implementation of multi-layer category function using ancestry "I tried to make a window with Bootstrap 3"
I tried to express the result of before and after of Date class with a number line
I tried to build the environment of PlantUML Server with Docker
I tried to interact with Java
I tried to make a machine learning application with Dash (+ Docker) part2 ~ Basic way of writing Dash ~
A story about hitting the League Of Legends API with JAVA
I tried to make an Android application with MVC now (Java)
I tried to check the operation of gRPC server with grpcurl
I tried to take a look at the flow of Android development environment construction with Android Studio
I tried to summarize the methods of Java String and StringBuilder
I made a tool to output the difference of CSV file
I tried to make a group function (bulletin board) with Rails
I tried to make a sample program using the problem of database specialist in Domain Driven Design
I tried to make a parent class of a value object in Ruby
[iOS] I tried to make a processing application like Instagram with Swift
I made a virtual currency arbitrage bot and tried to make money
I tried to make full use of the CPU core in Ruby
I tried to visualize the access of Lambda → Athena with AWS X-Ray
I tried to make a talk application in Java using AI "A3RT"
I tried to measure and compare the speed of GraalVM with JMH
I tried to summarize the Stream API
I tried to create a method to apply multiple filters at once with Java Stream API. Is this okay?
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
[LINE @] I tried to make a Japanese calendar Western calendar conversion BOT [Messaging API]
I tried to make a machine learning application with Dash (+ Docker) part3 ~ Practice ~
I tried to implement a function equivalent to Felica Lite with HCE-F of Android
What I tried when I wanted to get all the fields of a bean
I tried to make a simple game with Javafx ① "Let's find happiness game" (unfinished)
[Java] I tried to connect using a connection pool with Servlet (tomcat) & MySQL & Java
Rails6 I want to make an array of values with a check box
[Android] I tried to make a material list screen with ListView + Bottom Sheet
I tried to clone a web application full of bugs with Spring Boot
I tried to make a web application that searches tweets with vue-word cloud and examines the tendency of what is written in the associated profile
java I tried to break a simple block
I tried to develop a man-hour management tool
I did Java to make (a == 1 && a == 2 && a == 3) always true
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
[Ruby] I want to make a program that displays today's day of the week!
I tried to create a shopping site administrator function / screen with Java and Spring
A Java user over a dozen years ago tried to study the functions of Java8 (Generics).
I tried to make a simple game with Javafx ① "Let's find happiness game" (unfinished version ②)