Created
August 24, 2011 05:24
-
-
Save shazron/1167362 to your computer and use it in GitHub Desktop.
auto-ingest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.net.URL; | |
import java.net.URLEncoder; | |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import javax.net.ssl.HttpsURLConnection; | |
public class Autoingestion | |
{ | |
public Autoingestion() | |
{ | |
} | |
public static void main(String args[]) | |
throws Throwable | |
{ | |
HttpsURLConnection httpsurlconnection; | |
String s1; | |
if(args.length < 6 || args.length > 7) | |
{ | |
System.out.println("Please enter all the required parameters. For help, please download the latest User Guide from the Sales and Trends module in iTunes Connect."); | |
return; | |
} | |
String s = null; | |
if(args.length == 7 && null != args[6]) | |
{ | |
s = args[6]; | |
} else | |
{ | |
Calendar calendar = Calendar.getInstance(); | |
SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd"); | |
calendar.add(5, -1); | |
s = simpledateformat.format(calendar.getTime()).toString(); | |
} | |
httpsurlconnection = null; | |
Object obj = null; | |
s1 = (new StringBuilder()).append("USERNAME=").append(URLEncoder.encode(args[0], "UTF-8")).toString(); | |
s1 = (new StringBuilder()).append(s1).append("&PASSWORD=").append(URLEncoder.encode(args[1], "UTF-8")).toString(); | |
s1 = (new StringBuilder()).append(s1).append("&VNDNUMBER=").append(URLEncoder.encode(args[2], "UTF-8")).toString(); | |
s1 = (new StringBuilder()).append(s1).append("&TYPEOFREPORT=").append(URLEncoder.encode(args[3], "UTF-8")).toString(); | |
s1 = (new StringBuilder()).append(s1).append("&DATETYPE=").append(URLEncoder.encode(args[4], "UTF-8")).toString(); | |
s1 = (new StringBuilder()).append(s1).append("&REPORTTYPE=").append(URLEncoder.encode(args[5], "UTF-8")).toString(); | |
s1 = (new StringBuilder()).append(s1).append("&REPORTDATE=").append(URLEncoder.encode(s, "UTF-8")).toString(); | |
URL url = new URL("https://reportingitc.apple.com/autoingestion.tft?"); | |
httpsurlconnection = (HttpsURLConnection)url.openConnection(); | |
httpsurlconnection.setRequestMethod("POST"); | |
httpsurlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); | |
httpsurlconnection.setDoOutput(true); | |
OutputStreamWriter outputstreamwriter = new OutputStreamWriter(httpsurlconnection.getOutputStream()); | |
outputstreamwriter.write(s1); | |
outputstreamwriter.flush(); | |
outputstreamwriter.close(); | |
if(httpsurlconnection.getHeaderField("ERRORMSG") != null) | |
System.out.println(httpsurlconnection.getHeaderField("ERRORMSG")); | |
else | |
if(httpsurlconnection.getHeaderField("filename") != null) | |
getFile(httpsurlconnection); | |
if(httpsurlconnection != null) | |
{ | |
httpsurlconnection.disconnect(); | |
httpsurlconnection = null; | |
} | |
break MISSING_BLOCK_LABEL_468; | |
Exception exception; | |
exception; | |
exception.printStackTrace(); | |
System.out.println("The report you requested is not available at this time. Please try again in a few minutes."); | |
if(httpsurlconnection != null) | |
{ | |
httpsurlconnection.disconnect(); | |
httpsurlconnection = null; | |
} | |
break MISSING_BLOCK_LABEL_468; | |
Exception exception1; | |
exception1; | |
if(httpsurlconnection != null) | |
{ | |
httpsurlconnection.disconnect(); | |
httpsurlconnection = null; | |
} | |
throw exception1; | |
} | |
private static void getFile(HttpsURLConnection httpsurlconnection) | |
throws IOException | |
{ | |
String s = httpsurlconnection.getHeaderField("filename"); | |
System.out.println(s); | |
int i = 0; | |
BufferedInputStream bufferedinputstream = new BufferedInputStream(httpsurlconnection.getInputStream()); | |
BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(new FileOutputStream(s)); | |
byte abyte0[] = new byte[1024]; | |
while((i = bufferedinputstream.read(abyte0)) != -1) | |
bufferedoutputstream.write(abyte0, 0, i); | |
bufferedinputstream.close(); | |
bufferedoutputstream.close(); | |
System.out.println("File Downloaded Successfully "); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment