/* * [FetchDVDFacts.java] * * Summary: Get basic facts about a new DVD product from Amazon AWS API. Used to add new products. * * Copyright: (c) 2013-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2013-09-29 initial version */ package com.mindprod.aws; import com.mindprod.aws.jax.AWSECommerceService; import com.mindprod.aws.jax.AWSECommerceServicePortType; import com.mindprod.aws.jax.AwsHandlerResolver; import com.mindprod.aws.jax.Image; import com.mindprod.aws.jax.Item; import com.mindprod.aws.jax.ItemAttributes; import com.mindprod.aws.jax.ItemLookup; import com.mindprod.aws.jax.ItemLookupRequest; import com.mindprod.aws.jax.Items; import com.mindprod.aws.jax.OperationRequest; import com.mindprod.common18.EIO; import com.mindprod.common18.Misc; import com.mindprod.entities.EntifyStrings; import com.mindprod.fastcat.FastCat; import com.mindprod.filetransfer.FileTransfer; import com.mindprod.htmlmacros.macro.Global; import com.mindprod.htmlmacros.support.ConfigurationForMindprod; import com.mindprod.hunkio.HunkIO; import com.mindprod.stores.DStore; import javax.xml.namespace.QName; import javax.xml.ws.Holder; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import static java.lang.System.*; /** * Get basic facts about a new DVD product from Amazon AWS API. Used to add new products. *
* It does not fetch info about whether the products are in stock. * It does not fetch Tiger or Newegg info. * Needs ASIN-10 and UPC-12 on command line * * @author Roedy Green, Canadian Mind Products * @version 1.0 2013-09-29 initial version * @since 2013-09-29 */ public class FetchDVDFacts { // declarations /** * true if debugging, and want extra output */ private static final boolean DEBUGGING = false; /** * fetch confidential amazon.com-assigned awsAccessKeyId from environment set awsaccesskeyid=xxxxx */ private static final String AWS_ACCESS_KEY_ID = System.getenv( "awsaccesskeyid" ); /** * fetch confidential amazon.com-assigned awsSecretAccessKey assigned by Amazon set awssecretaccesskey=xxxxx */ private static final String AWS_SECRET_ACCESS_KEY = System.getenv( "awssecretaccesskey" ); /** * Nampspace for amazon.com in the USA. Would have to be modified for other countries. */ private static final String NAME_SPACE_URI = "http://webservices.amazon.com/AWSECommerceService/2013-08-01"; /** * name of the SOAP service */ private static final String QNAME = "AWSECommerceService"; private static final String USAGE = "\nFetchDVDFacts asin upc [-replace]"; /** * location of JAX schmo, locally cached. for amazon.com in the USA. Would have to be modified for other countries. * Original came from http://ecs.amazonaws.com/AWSECommerceService/AWSECommerceService.wsd */ private static final String WSDL_LOCATION = "file:///E:/com/mindprod/aws/jax/AWSECommerceService.wsdl"; /** * asin */ private static String asin; /** * fetch public amazon.com-assigned associateTag from environment set awsassociatetag=xxxxx */ private static String associateTag; /** * price * in form "$69.99" */ private static String price; /** * title of dvd */ private static String title; /** * upc */ private static String upc; /** * isbn */ private static String isbn13; /** * Which store do we want to probe for new products. */ private static DStore primaryDStore; /** * where Book cover images files are kept */ private static File DVDCoverDir; /** * where Book files are kept */ private static File DVDDir; // /declarations // methods /** * generate the xxxx.html file containing the DVD macro with info we gleaned from Amazon. * * @param target file where write generated DVD macro * * @throws java.io.IOException if trouble writing file */ private static void generate( final File target ) throws IOException { // does not handle birth/death final FastCat sb = new FastCat( 19 ); title = EntifyStrings.entifyHTML( title ); sb.append( "\n" ); sb.append( "\n" ); sb.append( "\n" ); final String generated = sb.toString(); HunkIO.writeEntireFile( target, generated, HunkIO.UTF8 ); out.println( EIO.getCanOrAbsPath( target ) + " written." ); } // /method /** * standard boilerplate to connect to amazon.com AWS server with SOAP * * @return port to use to send requests. * @throws java.net.MalformedURLException if some URLs were mis-specified in the following code. */ private static AWSECommerceServicePortType getPort() throws MalformedURLException { // Set the service: AWSECommerceService service = new AWSECommerceService( new URL( WSDL_LOCATION ), new QName( NAME_SPACE_URI, QNAME ) ); // AwsHandlerResolver does the timestamp, signing and Base64 encoding service.setHandlerResolver( new AwsHandlerResolver( AWS_SECRET_ACCESS_KEY ) ); // Set the service port: return primaryDStore.getPort( service ); } // /method /** * Probe the amazon AWS api for isbn13, results in class vars * * @param replace true if should replace existing image. * * @throws java.net.MalformedURLException if generated URL is malformed. */ private static void queryASIN( final boolean replace ) throws MalformedURLException { // for amazon.com in USA // define magic configuring strings final AWSECommerceServicePortType port = getPort(); // new ItemLookup final ItemLookup itemLookup = new ItemLookup(); // new ItemLookupRequest which is part of the ItemLookup final ItemLookupRequest itemLookupRequest = new ItemLookupRequest(); // odd our lookup request to the the Lookup. final List