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.
"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.
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".
--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.
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.
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)
AmazonAPI.java
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;
while(line[k]!=null){
stmp = MyParser.parseCSV(line[k]);
SC[j][k] = ShipmentCharge.MakeTable(SC[j][k], stmp, j);
k++;
}
}
// 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++){
arr[i].setCountry(ItemData.Countries[i]);
xml[i] = SearchAnItem.SearchByID(ItemData.getItemID(), i);
arr[i].setShitpment(dtmp[i]);
arr[i].setCurrenciesCode(MyParser.getTagElmFromXML(xml[i],tag[0]));
arr[i].setPrice( MyParser.Convert2Double(MyParser.getTagElmFromXML(xml[i],tag[1])));
arr[i].setCurrenciesRate(CurrenciesRate[i]);
arr[i].PrintAll();
}
}
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.
Thank you for reading this far, and I will post it if I make something again.
--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)
--Saturday and Sunday (important here)
--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