Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.46 KB | None | 0 0
  1. package EbayLister.com;
  2.  
  3. import java.awt.AWTException;
  4. import java.io.IOException;
  5. import java.util.Map;
  6. import java.util.TreeMap;
  7.  
  8. import org.codehaus.jettison.json.JSONException;
  9. import org.jsoup.Connection.Method;
  10. import org.jsoup.Connection.Response;
  11. import org.jsoup.Jsoup;
  12. import org.jsoup.nodes.Document;
  13. import org.jsoup.nodes.Element;
  14. import org.jsoup.parser.Parser;
  15. import org.jsoup.select.Elements;
  16.  
  17. import AmznTrackingPackage.AmznTrackingFunction;
  18. import EbayAssitivePackage.EbayApi;
  19. import EbayAssitivePackage.FixedPriceCalculation;
  20. import EbayTrackingPackage.EbayScrapeFunction;
  21.  
  22. public class EbayLister {
  23.  
  24.  
  25.  
  26. String amznAsin = "";
  27. String ackMessage = "Error";
  28.  
  29.  
  30.  
  31.  
  32.  
  33. public String getAmznAsin() {
  34. return amznAsin;
  35. }
  36.  
  37.  
  38.  
  39.  
  40. public String listAmazonItem(String amazonUrl, String titleToPost) throws IOException, JSONException, InterruptedException, AWTException {
  41. //-public static void main(String[] args) throws IOException, JSONException {-------------------***[Start]
  42. boolean posted = false;
  43. String ebayLink = null;
  44.  
  45. AmznTrackingFunction amzn = new AmznTrackingFunction(amazonUrl);
  46. boolean search = amzn.search();
  47. amznAsin = amzn.getAmznAsin();
  48.  
  49.  
  50. if(amzn.isListingVero() == true)
  51. {
  52.  
  53. System.out.println("--------------------ERROR----------------------------[START}\n" +
  54. "\n" +
  55. "\n" +
  56. "ITEM IS VERO PROTECTED: \n" +
  57. "\n" +
  58. "\n" +
  59. "\n" +
  60. "PLEASE ENTER VALID & UNPOSTED ITEM\n" +
  61. "\n" +
  62. "\n" +
  63. "\n" +
  64. "--------------------ERROR----------------------------[END]");
  65.  
  66. }
  67.  
  68. if(amzn.isItemOutOfStock() == true)
  69. {
  70.  
  71. System.out.println("--------------------ERROR----------------------------[START}\n" +
  72. "\n" +
  73. "\n" +
  74. "ITEM IS OUT OF STOCK: \n" +
  75. "\n" +
  76. "\n" +
  77. "\n" +
  78. "PLEASE ENTER VALID & UNPOSTED ITEM\n" +
  79. "\n" +
  80. "\n" +
  81. "\n" +
  82. "--------------------ERROR----------------------------[END]");
  83.  
  84. }
  85.  
  86.  
  87.  
  88. boolean isItemVero = amzn.isListingVero();
  89.  
  90. //isItemVero = false;
  91.  
  92. if(search==true && isItemVero == false && amzn.isItemOutOfStock() == false) {
  93.  
  94.  
  95. //------------------------------------if(search==true) {-------------------------------***[Start]
  96.  
  97. //System.out.println("starting Post");
  98.  
  99. String input = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
  100. "<AddFixedPriceItemRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\">\n" +
  101. " <RequesterCredentials>\n" +
  102. " <eBayAuthToken>YOURTOKENHERE</eBayAuthToken>\n" +
  103. " </RequesterCredentials>\n" +
  104. " <ErrorLanguage>en_CA</ErrorLanguage>\n" +
  105. " <WarningLevel>High</WarningLevel>\n" +
  106. " <Item>\n" +
  107. " <AutoPay>true</AutoPay>"+
  108. " <UseTaxTable>true</UseTaxTable>\n" +
  109. " <Title>Apple MacBook Pro MB990LL/A 13.3 in. Notebook NEW</Title>\n" +
  110. " <Description>Brand New Apple MacBook Pro MB990LL/A 13.3 in. Notebook!</Description>\n" +
  111. " <PrimaryCategory>\n" +
  112. " <CategoryID>111422</CategoryID>\n" +
  113. " </PrimaryCategory>\n" +
  114. " <SKU> SKUType (string) </SKU>\n"+
  115. " <StartPrice>500.0</StartPrice>\n" +
  116. " <CategoryMappingAllowed>true</CategoryMappingAllowed>\n" +
  117. " <ConditionID>1000</ConditionID>\n" +
  118. " <Country>CA</Country>\n" +
  119. " <Currency>CAD</Currency>\n" +
  120. " <DispatchTimeMax>3</DispatchTimeMax>\n" +
  121. " <ListingDuration>GTC</ListingDuration>\n" +
  122. " <ListingType>FixedPriceItem</ListingType>\n" +
  123. " <PaymentMethods>PayPal</PaymentMethods>\n" +
  124. " <PayPalEmailAddress>canadiandirectconsumer@gmail.com</PayPalEmailAddress>\n" +
  125. " <PictureDetails>\n" +
  126. " <GalleryType>Gallery</GalleryType>\n" +
  127. " <PhotoDisplay>PicturePack</PhotoDisplay>\n" +
  128. " <PictureURL>https://mypicserver.com/myphoto.jpg</PictureURL>\n" +
  129. " </PictureDetails>\n" +
  130. " <ItemSpecifics></ItemSpecifics>\n" +
  131. " <Location>Toronto, Ontario</Location>\n" +
  132. " <ProductListingDetails>\n" +
  133. " <BrandMPN></BrandMPN>\n" +
  134. " <IncludeStockPhotoURL>true</IncludeStockPhotoURL>\n" +
  135. " <IncludeeBayProductDetails>false</IncludeeBayProductDetails>\n" +
  136. " <UseFirstProduct>true</UseFirstProduct>\n" +
  137. " <UseStockPhotoURLAsGallery>true</UseStockPhotoURLAsGallery>\n" +
  138. " <ReturnSearchResultOnDuplicates>true</ReturnSearchResultOnDuplicates>\n" +
  139. " </ProductListingDetails>\n" +
  140. " <Quantity>1</Quantity>\n" +
  141. " <ReturnPolicy>\n" +
  142. " <ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>\n" +
  143. " <RefundOption>MoneyBack</RefundOption>\n" +
  144. " <ReturnsWithinOption>Days_30</ReturnsWithinOption>\n" +
  145. " <ShippingCostPaidByOption>Seller</ShippingCostPaidByOption>\n" +
  146. " </ReturnPolicy>\n" +
  147. " <ShippingDetails>\n" +
  148. " <ShippingType>Flat</ShippingType>\n" +
  149. " <ShippingServiceOptions>\n" +
  150. " <ShippingServicePriority>1</ShippingServicePriority>\n" +
  151. " <ShippingService>CA_StandardShipping</ShippingService>\n" +
  152. " <FreeShipping>true</FreeShipping>\n" +
  153. " <ShippingServiceAdditionalCost currencyID=\"CAD\">0.00</ShippingServiceAdditionalCost>\n" +
  154. " </ShippingServiceOptions>\n" +
  155. " </ShippingDetails>\n" +
  156. " <Site>Canada</Site>\n" +
  157. " </Item>\n" +
  158. "</AddFixedPriceItemRequest>";
  159.  
  160. Document xmlDoc = Jsoup.parse(input, "", Parser.xmlParser());
  161. xmlDoc.outputSettings().indentAmount(0).prettyPrint(false);
  162.  
  163. Element e = xmlDoc.select("eBayAuthToken").first();
  164. e.text(EbayAssitivePackage.Configuration.ProductionAuthToken);
  165.  
  166.  
  167.  
  168. e = xmlDoc.select("Title").first();
  169.  
  170. if(titleToPost == null)
  171. {
  172. e.text(EbayAssitivePackage.EbayTitleBuilder.titleBuilder(amzn));
  173. }
  174.  
  175. if(titleToPost != null)
  176. {
  177. e.text(titleToPost);
  178. }
  179.  
  180.  
  181.  
  182.  
  183. e = xmlDoc.select("Description").first();
  184. e.text(EbayAssitivePackage.DescriptionBuilder.buildHTML(amzn));
  185.  
  186. // category
  187. e = xmlDoc.select("CategoryID").first();
  188. boolean categoryCheck = false;
  189. do
  190. {
  191. try {
  192. e.text(EbayAssitivePackage.EbayApi.getSuggestedCategory(amzn.getAmazonTitle()));
  193. categoryCheck = true;
  194. }catch(Exception f) {
  195. f.printStackTrace();
  196. }
  197.  
  198.  
  199.  
  200. }while(categoryCheck == false);
  201.  
  202.  
  203. //pics
  204. e = xmlDoc.select("PictureDetails").first();
  205. e.text("");
  206.  
  207. boolean isImgfirstPhoto = true;
  208.  
  209. int x = 0;
  210.  
  211. for(String imgUrl: amzn.getAmazonHighResImgList())
  212. {
  213. try {
  214. System.out.println(imgUrl);
  215. System.out.println("Amazon Original Title: "+amzn.getAmazonTitle());
  216. String ebayPictureTitle = EbayAssitivePackage.EbayTitleBuilder.titleBuilder(amzn);
  217. System.out.println("ebayPictureTitle: "+ebayPictureTitle);
  218. String ebayPictureUrl = "";
  219.  
  220. int retries = 0;
  221. do
  222. {
  223. try {
  224. ebayPictureUrl = EbayApi.UploadSiteHostedPictures(imgUrl, ebayPictureTitle, isImgfirstPhoto);
  225. retries = 3;
  226. }catch(Exception f)
  227. {
  228. f.printStackTrace();
  229. }
  230.  
  231. retries++;
  232.  
  233. }while(retries < 3);
  234.  
  235.  
  236. if(ebayPictureUrl.contains("ebay"))
  237. {
  238. e.appendElement("PictureURL").text(ebayPictureUrl);
  239. }
  240.  
  241.  
  242.  
  243. isImgfirstPhoto = false;
  244.  
  245. }catch(Exception f) {
  246. f.printStackTrace();
  247. }
  248.  
  249.  
  250. x++;
  251. if(x == 12)
  252. {
  253. break;
  254. }
  255.  
  256.  
  257. }
  258.  
  259.  
  260. e = xmlDoc.select("StartPrice").first();
  261. double setFixedPrice = amzn.getAmznPrice()*1.13*1.45+0.30;
  262.  
  263.  
  264. if(titleToPost == null)
  265. {
  266. if(amzn.getAmznMerchant().contains("Amazon")) {
  267. setFixedPrice = FixedPriceCalculation.getFixedPriceAmazon(amzn.getAmznPrice());
  268. }
  269.  
  270. if(!amzn.getAmznMerchant().contains("Amazon")) {
  271. setFixedPrice = FixedPriceCalculation.getFixedPriceMerchant(amzn.getAmznPrice());
  272. }
  273. }
  274.  
  275.  
  276.  
  277.  
  278. e.text(Double.toString(setFixedPrice));
  279.  
  280.  
  281.  
  282. e = xmlDoc.select("SKU").first();
  283. e.text(amzn.getSku());
  284.  
  285.  
  286.  
  287. e = xmlDoc.select("BrandMPN").first();
  288. e.appendElement("Brand").text(amzn.getAmazonBrand());
  289. e.appendElement("MPN").text(amzn.getAmazonMpn());
  290.  
  291.  
  292.  
  293. //NameValueList
  294. //ItemSpecifics
  295.  
  296.  
  297. e = xmlDoc.select("ItemSpecifics").first();
  298. Map<String,String> amazonNameValueMap = amzn.getAmazonNameValueMap();
  299. Map<String, String> reversedMap = new TreeMap<String, String>(amazonNameValueMap);
  300.  
  301. for(int i = 0;i<reversedMap.size();i++) {
  302. e.appendElement("NameValueList");
  303. }
  304.  
  305.  
  306.  
  307.  
  308.  
  309. int i = 0;
  310. for (Map.Entry entry : reversedMap.entrySet()) {
  311. Element nameValueList = e.child(i);
  312.  
  313. String name = entry.getKey().toString();
  314. try {
  315. name = name.substring(0, 64);
  316. }catch(Exception f) {
  317. //f.printStackTrace();
  318. }
  319.  
  320. String value = entry.getValue().toString();
  321.  
  322. try {
  323. value = value.substring(0, 64);
  324. }catch(Exception f) {
  325. //f.printStackTrace();
  326. }
  327.  
  328.  
  329.  
  330. nameValueList.appendElement("Name").text(name);
  331. nameValueList.appendElement("Value").text(value);
  332. i++;
  333. }
  334.  
  335. e.appendElement("NameValueList");
  336. Element nameValueList = e.child(i);
  337. nameValueList.appendElement("Name").text("Brand");
  338. nameValueList.appendElement("Value").text(amzn.getAmazonBrand());
  339.  
  340. i++;
  341. e.appendElement("NameValueList");
  342. nameValueList = e.child(i);
  343. nameValueList.appendElement("Name").text("MPN");
  344. nameValueList.appendElement("Value").text(amzn.getAmazonMpn());
  345.  
  346. i++;
  347. e.appendElement("NameValueList");
  348. nameValueList = e.child(i);
  349. nameValueList.appendElement("Name").text("Model");
  350. nameValueList.appendElement("Value").text(amzn.getAmazonMpn());
  351.  
  352.  
  353. ///ProductListingDetails UPC
  354. e = xmlDoc.select("ProductListingDetails").first();
  355. e.appendElement("UPC").text(amzn.getAmazonUpc());
  356.  
  357. System.out.println("\n\n\n\n------------------------------------------------------------------------------\n\n\n\n\n");
  358. System.out.println(xmlDoc);
  359. System.out.println("------------------------------------------------------------------------------\n\n");
  360.  
  361.  
  362.  
  363.  
  364.  
  365. //--------------------------- Post XML -----------------------------
  366.  
  367.  
  368.  
  369. Response ebayRes =
  370. Jsoup.connect("https://api.ebay.com/ws/api.dll") //https://api.ebay.com/ws/api.dll
  371. .ignoreContentType(true)
  372. .ignoreHttpErrors(true)
  373.  
  374.  
  375. .header("Content-type", "text/xml")
  376. .header("X-EBAY-API-COMPATIBILITY-LEVEL", "911")
  377. .header("X-EBAY-API-SITEID", "2")
  378. .header("X-EBAY-API-CALL-NAME", "AddFixedPriceItem")
  379. .header("X-EBAY-API-APP-NAME", "TehseenA-hockeygr-PRD-8ea920fd0-0ada6f57")
  380. .header("X-EBAY-API-CERT-NAME", "PRD-ea920fd07393-3735-4b13-8fe1-ade8")
  381. .header("X-EBAY-API-DEV-NAME", "d58b693b-cfd5-4515-9b7d-e1432bbfb7d7")
  382. .requestBody(xmlDoc.toString())
  383.  
  384. .method(Method.POST)
  385. .execute()
  386. ;
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394. Document ebayDoc = ebayRes.parse();
  395. ebayDoc.outputSettings().indentAmount(3).prettyPrint(true);
  396. ebayLink = "https://www.ebay.ca/itm/"+ebayDoc.select("ItemId").text();
  397.  
  398. System.out.println(ebayDoc);
  399.  
  400. //System.out.println("\n\nSucessfully Listed: "+ebayLink+"\n");
  401.  
  402. posted = true;
  403. //------------------------------------if(search==true) {-------------------------------***[Finish]
  404.  
  405. ackMessage = ebayDoc.select("Ack").text();
  406.  
  407. Document ebayDocRetry = null;
  408. Document xmlDocumentToRetry = null;
  409.  
  410. if(ackMessage.toLowerCase().equals("failure"))
  411. {
  412. xmlDocumentToRetry = RelistXmlFunction.retryXml(ebayDoc.toString(), xmlDoc.toString());
  413.  
  414.  
  415. Response ResponseToRetry =
  416. Jsoup.connect("https://api.ebay.com/ws/api.dll") //https://api.ebay.com/ws/api.dll
  417. .ignoreContentType(true)
  418. .ignoreHttpErrors(true)
  419.  
  420.  
  421. .header("Content-type", "text/xml")
  422. .header("X-EBAY-API-COMPATIBILITY-LEVEL", "911")
  423. .header("X-EBAY-API-SITEID", "2")
  424. .header("X-EBAY-API-CALL-NAME", "AddFixedPriceItem")
  425. .header("X-EBAY-API-APP-NAME", "TehseenA-hockeygr-PRD-8ea920fd0-0ada6f57")
  426. .header("X-EBAY-API-CERT-NAME", "PRD-ea920fd07393-3735-4b13-8fe1-ade8")
  427. .header("X-EBAY-API-DEV-NAME", "d58b693b-cfd5-4515-9b7d-e1432bbfb7d7")
  428. .requestBody(xmlDocumentToRetry.toString())
  429.  
  430. .method(Method.POST)
  431. .execute()
  432. ;
  433.  
  434.  
  435. ebayDocRetry = ResponseToRetry.parse();
  436. ackMessage = ebayDocRetry.select("Ack").text();
  437.  
  438. ebayLink = "https://www.ebay.ca/itm/"+ebayDocRetry.select("ItemId").text();
  439.  
  440. System.out.println(ebayDocRetry);
  441.  
  442.  
  443. }
  444.  
  445.  
  446.  
  447. if(ackMessage.toLowerCase().equals("failure"))
  448. {
  449. Document xmlDocumentToRetry2 = RelistXmlFunction.retryXml(ebayDocRetry.toString(), xmlDocumentToRetry.toString());
  450.  
  451.  
  452. Response ResponseToRetry2 =
  453. Jsoup.connect("https://api.ebay.com/ws/api.dll") //https://api.ebay.com/ws/api.dll
  454. .ignoreContentType(true)
  455. .ignoreHttpErrors(true)
  456.  
  457.  
  458. .header("Content-type", "text/xml")
  459. .header("X-EBAY-API-COMPATIBILITY-LEVEL", "911")
  460. .header("X-EBAY-API-SITEID", "2")
  461. .header("X-EBAY-API-CALL-NAME", "AddFixedPriceItem")
  462. .header("X-EBAY-API-APP-NAME", "TehseenA-hockeygr-PRD-8ea920fd0-0ada6f57")
  463. .header("X-EBAY-API-CERT-NAME", "PRD-ea920fd07393-3735-4b13-8fe1-ade8")
  464. .header("X-EBAY-API-DEV-NAME", "d58b693b-cfd5-4515-9b7d-e1432bbfb7d7")
  465. .requestBody(xmlDocumentToRetry2.toString())
  466.  
  467. .method(Method.POST)
  468. .execute()
  469. ;
  470.  
  471.  
  472. Document ebayDocRetry2 = ResponseToRetry2.parse();
  473. ackMessage = ebayDocRetry2.select("Ack").text();
  474.  
  475. ebayLink = "https://www.ebay.ca/itm/"+ebayDocRetry2.select("ItemId").text();
  476.  
  477. System.out.println(ebayDocRetry2);
  478.  
  479.  
  480. }
  481.  
  482.  
  483.  
  484. }
  485. return ebayLink;
  486.  
  487. //-public static void main(String[] args) throws IOException, JSONException {-------------------***[Finish]
  488. }
  489.  
  490.  
  491.  
  492. public String listEbayItem(String ebayUrl) throws IOException, JSONException, InterruptedException {
  493. //-public static void main(String[] args) throws IOException, JSONException {-------------------***[Start]
  494. boolean posted = false;
  495. String ebayLink = null;
  496.  
  497. EbayScrapeFunction ebay = new EbayScrapeFunction(ebayUrl);
  498. boolean searchEbay = ebay.itemScrapeFunction();
  499.  
  500.  
  501. if(searchEbay==true) {
  502.  
  503. //------------------------------------if(search==true) {-------------------------------***[Start]
  504.  
  505.  
  506.  
  507. String input = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
  508. "<AddFixedPriceItemRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\">\n" +
  509. " <RequesterCredentials>\n" +
  510. " <eBayAuthToken>YOURTOKENHERE</eBayAuthToken>\n" +
  511. " </RequesterCredentials>\n" +
  512. " <ErrorLanguage>en_CA</ErrorLanguage>\n" +
  513. " <WarningLevel>High</WarningLevel>\n" +
  514. " <Item>\n" +
  515. " <AutoPay>true</AutoPay>" +
  516. " <UseTaxTable>true</UseTaxTable>\n" +
  517. " <Title>Apple MacBook Pro MB990LL/A 13.3 in. Notebook NEW</Title>\n" +
  518. " <Description>Brand New Apple MacBook Pro MB990LL/A 13.3 in. Notebook!</Description>\n" +
  519. " <PrimaryCategory>\n" +
  520. " <CategoryID>111422</CategoryID>\n" +
  521. " </PrimaryCategory>\n" +
  522. " <SKU></SKU>\n"+
  523. " <StartPrice>500.0</StartPrice>\n" +
  524. " <CategoryMappingAllowed>true</CategoryMappingAllowed>\n" +
  525. " <ConditionID>1000</ConditionID>\n" +
  526. " <Country>CA</Country>\n" +
  527. " <Currency>CAD</Currency>\n" +
  528. " <DispatchTimeMax>3</DispatchTimeMax>\n" +
  529. " <ListingDuration>Days_30</ListingDuration>\n" +
  530. " <ListingType>FixedPriceItem</ListingType>\n" +
  531. " <PaymentMethods>PayPal</PaymentMethods>\n" +
  532. " <PayPalEmailAddress>canadiandirectconsumer@gmail.com</PayPalEmailAddress>\n" +
  533. " <PictureDetails>\n" +
  534. " <PictureURL>https://mypicserver.com/myphoto.jpg</PictureURL>\n" +
  535. " </PictureDetails>\n" +
  536. " <ItemSpecifics></ItemSpecifics>\n" +
  537. " <Location>Toronto, Ontario</Location>\n" +
  538. " <ProductListingDetails>\n" +
  539. " <BrandMPN></BrandMPN>\n" +
  540. " <IncludeStockPhotoURL>true</IncludeStockPhotoURL>\n" +
  541. " <IncludeeBayProductDetails>false</IncludeeBayProductDetails>\n" +
  542. " <UseFirstProduct>true</UseFirstProduct>\n" +
  543. " <UseStockPhotoURLAsGallery>true</UseStockPhotoURLAsGallery>\n" +
  544. " <ReturnSearchResultOnDuplicates>true</ReturnSearchResultOnDuplicates>\n" +
  545. " </ProductListingDetails>\n" +
  546. " <Quantity>1</Quantity>\n" +
  547. " <ReturnPolicy>\n" +
  548. " <ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>\n" +
  549. " <RefundOption>MoneyBack</RefundOption>\n" +
  550. " <ReturnsWithinOption>Days_30</ReturnsWithinOption>\n" +
  551. " <ShippingCostPaidByOption>Seller</ShippingCostPaidByOption>\n" +
  552. " </ReturnPolicy>\n" +
  553. " <ShippingDetails>\n" +
  554. " <ShippingType>Flat</ShippingType>\n" +
  555. " <ShippingServiceOptions>\n" +
  556. " <ShippingServicePriority>1</ShippingServicePriority>\n" +
  557. " <ShippingService>CA_StandardShipping</ShippingService>\n" +
  558. " <FreeShipping>true</FreeShipping>\n" +
  559. " <ShippingServiceAdditionalCost currencyID=\"CAD\">0.00</ShippingServiceAdditionalCost>\n" +
  560. " </ShippingServiceOptions>\n" +
  561. " </ShippingDetails>\n" +
  562. " <Site>Canada</Site>\n" +
  563. " </Item>\n" +
  564. "</AddFixedPriceItemRequest>";
  565.  
  566. Document xmlDoc = Jsoup.parse(input, "", Parser.xmlParser());
  567. xmlDoc.outputSettings().indentAmount(0).prettyPrint(false);
  568.  
  569. Element e = xmlDoc.select("eBayAuthToken").first();
  570. e.text(EbayAssitivePackage.Configuration.ProductionAuthToken);
  571.  
  572.  
  573.  
  574. e = xmlDoc.select("Title").first();
  575. e.text(ebay.getEbayOriginalTitle());
  576.  
  577.  
  578.  
  579. e = xmlDoc.select("Description").first();
  580. e.text(ebay.getEbayDescription());
  581.  
  582. //category
  583. e = xmlDoc.select("CategoryID").first();
  584.  
  585. if(ebay.getCategoryId() == null || ebay.getCategoryId().isEmpty() || ebay.getCategoryId().contains("9999"))
  586. {
  587.  
  588.  
  589.  
  590. boolean categoryCheck = false;
  591. do
  592. {
  593. try
  594. {
  595. e.text(EbayAssitivePackage.EbayApi.getSuggestedCategory(ebay.getEbayOriginalTitle()));
  596. categoryCheck = true;
  597. }catch(Exception f) {
  598. f.printStackTrace();
  599. }
  600.  
  601.  
  602.  
  603.  
  604. }while(categoryCheck == false);
  605.  
  606. }else
  607. {
  608. e.text(ebay.getCategoryId());
  609.  
  610. }
  611.  
  612.  
  613.  
  614. e = xmlDoc.select("PictureDetails").first();
  615. e.text("");
  616.  
  617.  
  618. int x = 0;
  619.  
  620. for(String imgUrl: ebay.getEbayImgList())
  621. {
  622. e.appendElement("PictureURL").text(imgUrl);
  623. x++;
  624.  
  625. if(x == 12)
  626. {
  627. break;
  628. }
  629. }
  630.  
  631.  
  632.  
  633. double setFixedPrice = ebay.getEbayPrice() - 0.07;;
  634. setFixedPrice = (double) Math.round(setFixedPrice * 100) / 100;
  635.  
  636. e = xmlDoc.select("StartPrice").first();
  637. e.text(Double.toString(setFixedPrice));
  638.  
  639. e = xmlDoc.select("BrandMPN").first();
  640. e.appendElement("Brand").text(ebay.getEbayBrand());
  641. e.appendElement("MPN").text(ebay.getEbayMpn());
  642.  
  643.  
  644. //NameValueList
  645. //ItemSpecifics
  646. e = xmlDoc.select("ItemSpecifics").first();
  647. Map<String,String> ebayNameValueMap = ebay.getEbayNameValueMap();
  648. Map<String, String> reversedMap = new TreeMap<String, String>(ebayNameValueMap);
  649.  
  650. for(int i = 0;i<reversedMap.size();i++) {
  651. e.appendElement("NameValueList");
  652. }
  653.  
  654.  
  655. int i = 0;
  656. for (Map.Entry entry : reversedMap.entrySet()) {
  657. Element nameValueList = e.child(i);
  658.  
  659. String name = entry.getKey().toString();
  660. try {
  661. name = name.substring(0, 64);
  662. }catch(Exception f) {
  663. f.printStackTrace();
  664. }
  665.  
  666. String value = entry.getValue().toString();
  667.  
  668. try {
  669. value = value.substring(0, 64);
  670. }catch(Exception f) {
  671. //f.printStackTrace();
  672. }
  673.  
  674.  
  675.  
  676. nameValueList.appendElement("Name").text(name);
  677. nameValueList.appendElement("Value").text(value);
  678. i++;
  679. }
  680.  
  681.  
  682. e.appendElement("NameValueList");
  683. Element nameValueList = e.child(i);
  684. nameValueList.appendElement("Name").text("Brand");
  685. nameValueList.appendElement("Value").text(ebay.getEbayBrand());
  686.  
  687. i++;
  688. e.appendElement("NameValueList");
  689. nameValueList = e.child(i);
  690. nameValueList.appendElement("Name").text("MPN");
  691. nameValueList.appendElement("Value").text(ebay.getEbayMpn());
  692.  
  693.  
  694. i++;
  695. e.appendElement("NameValueList");
  696. nameValueList = e.child(i);
  697. nameValueList.appendElement("Name").text("Model");
  698. nameValueList.appendElement("Value").text(ebay.getEbayMpn());
  699.  
  700.  
  701. //ProductListingDetails UPC
  702. e = xmlDoc.select("ProductListingDetails").first();
  703. e.appendElement("UPC").text(ebay.getEbayUpc());
  704.  
  705. System.out.println("------------------------------------------------------------------------------\n\n");
  706. System.out.println(xmlDoc);
  707. System.out.println("------------------------------------------------------------------------------\n\n");
  708.  
  709.  
  710.  
  711.  
  712.  
  713. //--------------------------- Post XML -----------------------------
  714.  
  715.  
  716.  
  717. Response ebayRes =
  718. Jsoup.connect("https://api.ebay.com/ws/api.dll") //https://api.ebay.com/ws/api.dll
  719. .ignoreContentType(true)
  720. .ignoreHttpErrors(true)
  721.  
  722.  
  723. .header("Content-type", "text/xml")
  724. .header("X-EBAY-API-COMPATIBILITY-LEVEL", "911")
  725. .header("X-EBAY-API-SITEID", "2")
  726. .header("X-EBAY-API-CALL-NAME", "AddFixedPriceItem")
  727. .header("X-EBAY-API-APP-NAME", "TehseenA-hockeygr-PRD-8ea920fd0-0ada6f57")
  728. .header("X-EBAY-API-CERT-NAME", "PRD-ea920fd07393-3735-4b13-8fe1-ade8")
  729. .header("X-EBAY-API-DEV-NAME", "d58b693b-cfd5-4515-9b7d-e1432bbfb7d7")
  730. .requestBody(xmlDoc.toString())
  731.  
  732. .method(Method.POST)
  733. .execute()
  734. ;
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742. Document ebayDoc = ebayRes.parse();
  743. ebayDoc.outputSettings().indentAmount(3).prettyPrint(true);
  744. ebayLink = "https://www.ebay.ca/itm/"+ebayDoc.select("ItemId").text();
  745.  
  746. System.out.println(ebayDoc);
  747. System.out.println("\n\nSucessfully Listed: "+ebayLink+"\n");
  748.  
  749. posted = true;
  750. //------------------------------------if(search==true) {-------------------------------***[Finish]
  751. }
  752. return ebayLink;
  753.  
  754. //-public static void main(String[] args) throws IOException, JSONException {-------------------***[Finish]
  755. }
  756.  
  757. public String listEbayWithTrackingItem(String ebayUrl, String amazonUrl) throws IOException, JSONException, InterruptedException, AWTException {
  758. //-public static void main(String[] args) throws IOException, JSONException {-------------------***[Start]
  759. boolean posted = false;
  760. String ebayLink = null;
  761.  
  762. EbayScrapeFunction ebay = new EbayScrapeFunction(ebayUrl);
  763. boolean searchEbay = ebay.itemScrapeFunction();
  764.  
  765. AmznTrackingFunction amzn = new AmznTrackingFunction(amazonUrl);
  766. boolean search = amzn.search();
  767. amznAsin = amzn.getAmznAsin();
  768.  
  769. if(amzn.isListingVero() == true)
  770. {
  771.  
  772. System.out.println("--------------------ERROR----------------------------[START}\n" +
  773. "\n" +
  774. "\n" +
  775. "ITEM IS VERO PROTECTED: \n" +
  776. "\n" +
  777. "\n" +
  778. "\n" +
  779. "PLEASE ENTER VALID & UNPOSTED ITEM\n" +
  780. "\n" +
  781. "\n" +
  782. "\n" +
  783. "--------------------ERROR----------------------------[END]");
  784.  
  785. }
  786.  
  787.  
  788.  
  789. if(amzn.isItemOutOfStock() == true)
  790. {
  791.  
  792. System.out.println("--------------------ERROR----------------------------[START}\n" +
  793. "\n" +
  794. "\n" +
  795. "ITEM IS OUT OF STOCK: \n" +
  796. "\n" +
  797. "\n" +
  798. "\n" +
  799. "PLEASE ENTER VALID & UNPOSTED ITEM\n" +
  800. "\n" +
  801. "\n" +
  802. "\n" +
  803. "--------------------ERROR----------------------------[END]");
  804.  
  805. }
  806.  
  807.  
  808.  
  809. if(search==true && searchEbay==true && amzn.isListingVero() == false && amzn.isItemOutOfStock() == false) {
  810.  
  811. //------------------------------------if(search==true) {-------------------------------***[Start]
  812.  
  813.  
  814.  
  815. String input = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
  816. "<AddFixedPriceItemRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\">\n" +
  817. " <RequesterCredentials>\n" +
  818. " <eBayAuthToken>YOURTOKENHERE</eBayAuthToken>\n" +
  819. " </RequesterCredentials>\n" +
  820. " <ErrorLanguage>en_CA</ErrorLanguage>\n" +
  821. " <WarningLevel>High</WarningLevel>\n" +
  822. " <Item>\n" +
  823. " <AutoPay>true</AutoPay>" +
  824. " <UseTaxTable>true</UseTaxTable>\n" +
  825. " <Title>Apple MacBook Pro MB990LL/A 13.3 in. Notebook NEW</Title>\n" +
  826. " <Description>Brand New Apple MacBook Pro MB990LL/A 13.3 in. Notebook!</Description>\n" +
  827. " <PrimaryCategory>\n" +
  828. " <CategoryID>111422</CategoryID>\n" +
  829. " </PrimaryCategory>\n" +
  830. " <SKU> SKUType (string) </SKU>\n"+
  831. " <StartPrice>500.0</StartPrice>\n" +
  832. " <CategoryMappingAllowed>true</CategoryMappingAllowed>\n" +
  833. " <ConditionID>1000</ConditionID>\n" +
  834. " <Country>CA</Country>\n" +
  835. " <Currency>CAD</Currency>\n" +
  836. " <DispatchTimeMax>3</DispatchTimeMax>\n" +
  837. " <ListingDuration>GTC</ListingDuration>\n" +
  838. " <ListingType>FixedPriceItem</ListingType>\n" +
  839. " <PaymentMethods>PayPal</PaymentMethods>\n" +
  840. " <PayPalEmailAddress>canadiandirectconsumer@gmail.com</PayPalEmailAddress>\n" +
  841. " <PictureDetails>\n" +
  842. " <PictureURL>https://mypicserver.com/myphoto.jpg</PictureURL>\n" +
  843. " </PictureDetails>\n" +
  844. " <ItemSpecifics></ItemSpecifics>\n" +
  845. " <Location>Toronto, Ontario</Location>\n" +
  846. " <ProductListingDetails>\n" +
  847. " <BrandMPN></BrandMPN>\n" +
  848. " <IncludeStockPhotoURL>true</IncludeStockPhotoURL>\n" +
  849. " <IncludeeBayProductDetails>true</IncludeeBayProductDetails>\n" +
  850. " <UseFirstProduct>true</UseFirstProduct>\n" +
  851. " <UseStockPhotoURLAsGallery>true</UseStockPhotoURLAsGallery>\n" +
  852. " <ReturnSearchResultOnDuplicates>true</ReturnSearchResultOnDuplicates>\n" +
  853. " </ProductListingDetails>\n" +
  854. " <Quantity>1</Quantity>\n" +
  855. " <ReturnPolicy>\n" +
  856. " <ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>\n" +
  857. " <RefundOption>MoneyBack</RefundOption>\n" +
  858. " <ReturnsWithinOption>Days_14</ReturnsWithinOption>\n" +
  859. " <ShippingCostPaidByOption>Seller</ShippingCostPaidByOption>\n" +
  860. " </ReturnPolicy>\n" +
  861. " <ShippingDetails>\n" +
  862. " <ShippingType>Flat</ShippingType>\n" +
  863. " <ShippingServiceOptions>\n" +
  864. " <ShippingServicePriority>1</ShippingServicePriority>\n" +
  865. " <ShippingService>CA_StandardShipping</ShippingService>\n" +
  866. " <FreeShipping>true</FreeShipping>\n" +
  867. " <ShippingServiceAdditionalCost currencyID=\"CAD\">0.00</ShippingServiceAdditionalCost>\n" +
  868. " </ShippingServiceOptions>\n" +
  869. " </ShippingDetails>\n" +
  870. " <Site>Canada</Site>\n" +
  871. " </Item>\n" +
  872. "</AddFixedPriceItemRequest>";
  873.  
  874. Document xmlDoc = Jsoup.parse(input, "", Parser.xmlParser());
  875. xmlDoc.outputSettings().indentAmount(0).prettyPrint(false);
  876.  
  877. Element e = xmlDoc.select("eBayAuthToken").first();
  878. e.text(EbayAssitivePackage.Configuration.ProductionAuthToken);
  879.  
  880.  
  881.  
  882. e = xmlDoc.select("Title").first();
  883. e.text(ebay.getEbayOriginalTitle());
  884.  
  885.  
  886.  
  887. e = xmlDoc.select("Description").first();
  888. e.text(EbayAssitivePackage.DescriptionBuilder.buildHTML(amzn));
  889.  
  890.  
  891. e = xmlDoc.select("CategoryID").first();
  892. if(ebay.getCategoryId() == null || ebay.getCategoryId().isEmpty() || ebay.getCategoryId().contains("9999"))
  893. {
  894.  
  895. boolean categoryCheck = false;
  896.  
  897. do
  898. {
  899. try {
  900. e.text(EbayAssitivePackage.EbayApi.getSuggestedCategory(ebay.getEbayOriginalTitle()));
  901. categoryCheck = true;
  902. }catch(Exception f) {
  903. f.printStackTrace();
  904. }
  905.  
  906.  
  907.  
  908.  
  909. }while(categoryCheck == false);
  910.  
  911.  
  912.  
  913. }else {
  914. e.text(ebay.getCategoryId());
  915.  
  916. }
  917.  
  918. e = xmlDoc.select("PictureDetails").first();
  919. e.text("");
  920.  
  921.  
  922. int x = 0;
  923. for(String imgUrl: ebay.getEbayImgList())
  924. {
  925. e.appendElement("PictureURL").text(imgUrl);
  926.  
  927.  
  928. x++;
  929. if(x == 12)
  930. {
  931. break;
  932. }
  933. }
  934.  
  935.  
  936. double setFixedPrice = ebay.getEbayPrice() - 0.07;;
  937. setFixedPrice = (double) Math.round(setFixedPrice * 100) / 100;
  938.  
  939. e = xmlDoc.select("StartPrice").first();
  940. e.text(Double.toString(setFixedPrice));
  941.  
  942.  
  943. e = xmlDoc.select("SKU").first();
  944. e.text(amzn.getSku());
  945.  
  946.  
  947. e = xmlDoc.select("BrandMPN").first();
  948. e.appendElement("Brand").text(amzn.getAmazonBrand());
  949. e.appendElement("MPN").text(amzn.getAmazonMpn());
  950.  
  951. //NameValueList
  952. //ItemSpecifics
  953. e = xmlDoc.select("ItemSpecifics").first();
  954. Map<String,String> amazonNameValueMap = amzn.getAmazonNameValueMap();
  955. Map<String, String> reversedMap = new TreeMap<String, String>(amazonNameValueMap);
  956.  
  957. for(int i = 0;i<reversedMap.size();i++) {
  958. e.appendElement("NameValueList");
  959. }
  960.  
  961.  
  962. int i = 0;
  963. for (Map.Entry entry : reversedMap.entrySet()) {
  964. Element nameValueList = e.child(i);
  965.  
  966. String name = entry.getKey().toString();
  967. try {
  968. name = name.substring(0, 64);
  969. }catch(Exception f) {
  970. f.printStackTrace();
  971. }
  972.  
  973. String value = entry.getValue().toString();
  974.  
  975. try {
  976. value = value.substring(0, 64);
  977. }catch(Exception f) {
  978. //f.printStackTrace();
  979. }
  980.  
  981.  
  982.  
  983. nameValueList.appendElement("Name").text(name);
  984. nameValueList.appendElement("Value").text(value);
  985. i++;
  986. }
  987.  
  988. e.appendElement("NameValueList");
  989. Element nameValueList = e.child(i);
  990. nameValueList.appendElement("Name").text("Brand");
  991. nameValueList.appendElement("Value").text(amzn.getAmazonBrand());
  992. i++;
  993.  
  994. e.appendElement("NameValueList");
  995. nameValueList = e.child(i);
  996. nameValueList.appendElement("Name").text("MPN");
  997. nameValueList.appendElement("Value").text(amzn.getAmazonMpn());
  998.  
  999. i++;
  1000. e.appendElement("NameValueList");
  1001. nameValueList = e.child(i);
  1002. nameValueList.appendElement("Name").text("Model");
  1003. nameValueList.appendElement("Value").text(amzn.getAmazonMpn());
  1004.  
  1005.  
  1006. //StartPrice
  1007.  
  1008. //ProductListingDetails
  1009. e = xmlDoc.select("ProductListingDetails").first();
  1010. e.appendElement("UPC").text(ebay.getEbayUpc());
  1011.  
  1012.  
  1013.  
  1014. //System.out.println("------------------------------------------------------------------------------\n\n");
  1015. //System.out.println(xmlDoc);
  1016. //System.out.println("------------------------------------------------------------------------------\n\n");
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022. //--------------------------- Post XML -----------------------------
  1023.  
  1024.  
  1025.  
  1026. Response ebayRes =
  1027. Jsoup.connect("https://api.ebay.com/ws/api.dll") //https://api.ebay.com/ws/api.dll
  1028. .ignoreContentType(true)
  1029. .ignoreHttpErrors(true)
  1030.  
  1031.  
  1032. .header("Content-type", "text/xml")
  1033. .header("X-EBAY-API-COMPATIBILITY-LEVEL", "911")
  1034. .header("X-EBAY-API-SITEID", "2")
  1035. .header("X-EBAY-API-CALL-NAME", "AddFixedPriceItem")
  1036. .header("X-EBAY-API-APP-NAME", "TehseenA-hockeygr-PRD-8ea920fd0-0ada6f57")
  1037. .header("X-EBAY-API-CERT-NAME", "PRD-ea920fd07393-3735-4b13-8fe1-ade8")
  1038. .header("X-EBAY-API-DEV-NAME", "d58b693b-cfd5-4515-9b7d-e1432bbfb7d7")
  1039. .requestBody(xmlDoc.toString())
  1040.  
  1041. .method(Method.POST)
  1042. .execute()
  1043. ;
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051. Document ebayDoc = ebayRes.parse();
  1052. ebayDoc.outputSettings().indentAmount(3).prettyPrint(true);
  1053. ebayLink = "https://www.ebay.ca/itm/"+ebayDoc.select("ItemId").text();
  1054.  
  1055. //System.out.println(ebayDoc);
  1056.  
  1057. //System.out.println("\n\nSucessfully Listed: "+ebayLink+"\n");
  1058.  
  1059.  
  1060. ackMessage = ebayDoc.select("Ack").text();
  1061.  
  1062. Document ebayDocRetry = null;
  1063. Document xmlDocumentToRetry = null;
  1064.  
  1065. if(ackMessage.toLowerCase().equals("failure"))
  1066. {
  1067. xmlDocumentToRetry = RelistXmlFunction.retryXml(ebayDoc.toString(), xmlDoc.toString());
  1068.  
  1069.  
  1070. Response ResponseToRetry =
  1071. Jsoup.connect("https://api.ebay.com/ws/api.dll") //https://api.ebay.com/ws/api.dll
  1072. .ignoreContentType(true)
  1073. .ignoreHttpErrors(true)
  1074.  
  1075.  
  1076. .header("Content-type", "text/xml")
  1077. .header("X-EBAY-API-COMPATIBILITY-LEVEL", "911")
  1078. .header("X-EBAY-API-SITEID", "2")
  1079. .header("X-EBAY-API-CALL-NAME", "AddFixedPriceItem")
  1080. .header("X-EBAY-API-APP-NAME", "TehseenA-hockeygr-PRD-8ea920fd0-0ada6f57")
  1081. .header("X-EBAY-API-CERT-NAME", "PRD-ea920fd07393-3735-4b13-8fe1-ade8")
  1082. .header("X-EBAY-API-DEV-NAME", "d58b693b-cfd5-4515-9b7d-e1432bbfb7d7")
  1083. .requestBody(xmlDocumentToRetry.toString())
  1084.  
  1085. .method(Method.POST)
  1086. .execute()
  1087. ;
  1088.  
  1089.  
  1090. ebayDocRetry = ResponseToRetry.parse();
  1091. ackMessage = ebayDocRetry.select("Ack").text();
  1092.  
  1093. ebayLink = "https://www.ebay.ca/itm/"+ebayDocRetry.select("ItemId").text();
  1094.  
  1095. System.out.println(ebayDocRetry);
  1096.  
  1097.  
  1098. }
  1099.  
  1100.  
  1101.  
  1102. if(ackMessage.toLowerCase().equals("failure"))
  1103. {
  1104. Document xmlDocumentToRetry2 = RelistXmlFunction.retryXml(ebayDocRetry.toString(), xmlDocumentToRetry.toString());
  1105.  
  1106.  
  1107. Response ResponseToRetry2 =
  1108. Jsoup.connect("https://api.ebay.com/ws/api.dll") //https://api.ebay.com/ws/api.dll
  1109. .ignoreContentType(true)
  1110. .ignoreHttpErrors(true)
  1111.  
  1112.  
  1113. .header("Content-type", "text/xml")
  1114. .header("X-EBAY-API-COMPATIBILITY-LEVEL", "911")
  1115. .header("X-EBAY-API-SITEID", "2")
  1116. .header("X-EBAY-API-CALL-NAME", "AddFixedPriceItem")
  1117. .header("X-EBAY-API-APP-NAME", "TehseenA-hockeygr-PRD-8ea920fd0-0ada6f57")
  1118. .header("X-EBAY-API-CERT-NAME", "PRD-ea920fd07393-3735-4b13-8fe1-ade8")
  1119. .header("X-EBAY-API-DEV-NAME", "d58b693b-cfd5-4515-9b7d-e1432bbfb7d7")
  1120. .requestBody(xmlDocumentToRetry2.toString())
  1121.  
  1122. .method(Method.POST)
  1123. .execute()
  1124. ;
  1125.  
  1126.  
  1127. Document ebayDocRetry2 = ResponseToRetry2.parse();
  1128. ackMessage = ebayDocRetry2.select("Ack").text();
  1129.  
  1130. ebayLink = "https://www.ebay.ca/itm/"+ebayDocRetry2.select("ItemId").text();
  1131.  
  1132. System.out.println(ebayDocRetry2);
  1133.  
  1134.  
  1135. }
  1136.  
  1137. posted = true;
  1138. //------------------------------------if(search==true) {-------------------------------***[Finish]
  1139. }
  1140. return ebayLink;
  1141.  
  1142. //-public static void main(String[] args) throws IOException, JSONException {-------------------***[Finish]
  1143. }
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152. public String listEbayWithTrackingItemOriginalImages(String ebayUrl, String amazonUrl) throws IOException, JSONException, InterruptedException, AWTException {
  1153. //-public static void main(String[] args) throws IOException, JSONException {-------------------***[Start]
  1154. boolean posted = false;
  1155. String ebayLink = null;
  1156.  
  1157. EbayScrapeFunction ebay = new EbayScrapeFunction(ebayUrl);
  1158. boolean searchEbay = ebay.itemScrapeFunction();
  1159.  
  1160. AmznTrackingFunction amzn = new AmznTrackingFunction(amazonUrl);
  1161. boolean search = amzn.search();
  1162. amznAsin = amzn.getAmznAsin();
  1163.  
  1164. if(amzn.isListingVero() == true)
  1165. {
  1166.  
  1167. System.out.println("--------------------ERROR----------------------------[START}\n" +
  1168. "\n" +
  1169. "\n" +
  1170. "ITEM IS VERO PROTECTED: \n" +
  1171. "\n" +
  1172. "\n" +
  1173. "\n" +
  1174. "PLEASE ENTER VALID & UNPOSTED ITEM\n" +
  1175. "\n" +
  1176. "\n" +
  1177. "\n" +
  1178. "--------------------ERROR----------------------------[END]");
  1179.  
  1180. }
  1181.  
  1182.  
  1183.  
  1184. if(amzn.isItemOutOfStock() == true)
  1185. {
  1186.  
  1187. System.out.println("--------------------ERROR----------------------------[START}\n" +
  1188. "\n" +
  1189. "\n" +
  1190. "ITEM IS OUT OF STOCK: \n" +
  1191. "\n" +
  1192. "\n" +
  1193. "\n" +
  1194. "PLEASE ENTER VALID & UNPOSTED ITEM\n" +
  1195. "\n" +
  1196. "\n" +
  1197. "\n" +
  1198. "--------------------ERROR----------------------------[END]");
  1199.  
  1200. }
  1201.  
  1202.  
  1203.  
  1204. if(search==true && searchEbay==true && amzn.isListingVero() == false && amzn.isItemOutOfStock() == false) {
  1205.  
  1206. //------------------------------------if(search==true) {-------------------------------***[Start]
  1207.  
  1208.  
  1209.  
  1210. String input = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
  1211. "<AddFixedPriceItemRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\">\n" +
  1212. " <RequesterCredentials>\n" +
  1213. " <eBayAuthToken>YOURTOKENHERE</eBayAuthToken>\n" +
  1214. " </RequesterCredentials>\n" +
  1215. " <ErrorLanguage>en_CA</ErrorLanguage>\n" +
  1216. " <WarningLevel>High</WarningLevel>\n" +
  1217. " <Item>\n" +
  1218. " <AutoPay>true</AutoPay>" +
  1219. " <UseTaxTable>true</UseTaxTable>\n" +
  1220. " <Title>Apple MacBook Pro MB990LL/A 13.3 in. Notebook NEW</Title>\n" +
  1221. " <Description>Brand New Apple MacBook Pro MB990LL/A 13.3 in. Notebook!</Description>\n" +
  1222. " <PrimaryCategory>\n" +
  1223. " <CategoryID>111422</CategoryID>\n" +
  1224. " </PrimaryCategory>\n" +
  1225. " <SKU> SKUType (string) </SKU>\n"+
  1226. " <StartPrice>500.0</StartPrice>\n" +
  1227. " <CategoryMappingAllowed>true</CategoryMappingAllowed>\n" +
  1228. " <ConditionID>1000</ConditionID>\n" +
  1229. " <Country>CA</Country>\n" +
  1230. " <Currency>CAD</Currency>\n" +
  1231. " <DispatchTimeMax>3</DispatchTimeMax>\n" +
  1232. " <ListingDuration>GTC</ListingDuration>\n" +
  1233. " <ListingType>FixedPriceItem</ListingType>\n" +
  1234. " <PaymentMethods>PayPal</PaymentMethods>\n" +
  1235. " <PayPalEmailAddress>canadiandirectconsumer@gmail.com</PayPalEmailAddress>\n" +
  1236. " <PictureDetails>\n" +
  1237. " <PictureURL>https://mypicserver.com/myphoto.jpg</PictureURL>\n" +
  1238. " </PictureDetails>\n" +
  1239. " <ItemSpecifics></ItemSpecifics>\n" +
  1240. " <Location>Toronto, Ontario</Location>\n" +
  1241. " <ProductListingDetails>\n" +
  1242. " <BrandMPN></BrandMPN>\n" +
  1243. " <IncludeStockPhotoURL>true</IncludeStockPhotoURL>\n" +
  1244. " <IncludeeBayProductDetails>true</IncludeeBayProductDetails>\n" +
  1245. " <UseFirstProduct>true</UseFirstProduct>\n" +
  1246. " <UseStockPhotoURLAsGallery>true</UseStockPhotoURLAsGallery>\n" +
  1247. " <ReturnSearchResultOnDuplicates>true</ReturnSearchResultOnDuplicates>\n" +
  1248. " </ProductListingDetails>\n" +
  1249. " <Quantity>1</Quantity>\n" +
  1250. " <ReturnPolicy>\n" +
  1251. " <ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>\n" +
  1252. " <RefundOption>MoneyBack</RefundOption>\n" +
  1253. " <ReturnsWithinOption>Days_14</ReturnsWithinOption>\n" +
  1254. " <ShippingCostPaidByOption>Seller</ShippingCostPaidByOption>\n" +
  1255. " </ReturnPolicy>\n" +
  1256. " <ShippingDetails>\n" +
  1257. " <ShippingType>Flat</ShippingType>\n" +
  1258. " <ShippingServiceOptions>\n" +
  1259. " <ShippingServicePriority>1</ShippingServicePriority>\n" +
  1260. " <ShippingService>CA_StandardShipping</ShippingService>\n" +
  1261. " <FreeShipping>true</FreeShipping>\n" +
  1262. " <ShippingServiceAdditionalCost currencyID=\"CAD\">0.00</ShippingServiceAdditionalCost>\n" +
  1263. " </ShippingServiceOptions>\n" +
  1264. " </ShippingDetails>\n" +
  1265. " <Site>Canada</Site>\n" +
  1266. " </Item>\n" +
  1267. "</AddFixedPriceItemRequest>";
  1268.  
  1269. Document xmlDoc = Jsoup.parse(input, "", Parser.xmlParser());
  1270. xmlDoc.outputSettings().indentAmount(0).prettyPrint(false);
  1271.  
  1272. Element e = xmlDoc.select("eBayAuthToken").first();
  1273. e.text(EbayAssitivePackage.Configuration.ProductionAuthToken);
  1274.  
  1275.  
  1276.  
  1277. e = xmlDoc.select("Title").first();
  1278. e.text(ebay.getEbayOriginalTitle());
  1279.  
  1280.  
  1281.  
  1282. e = xmlDoc.select("Description").first();
  1283. e.text(EbayAssitivePackage.DescriptionBuilder.buildHTML(amzn));
  1284.  
  1285.  
  1286. e = xmlDoc.select("CategoryID").first();
  1287. if(ebay.getCategoryId() == null || ebay.getCategoryId().isEmpty() || ebay.getCategoryId().contains("9999"))
  1288. {
  1289.  
  1290. boolean categoryCheck = false;
  1291.  
  1292. do
  1293. {
  1294. try {
  1295. e.text(EbayAssitivePackage.EbayApi.getSuggestedCategory(ebay.getEbayOriginalTitle()));
  1296. categoryCheck = true;
  1297. }catch(Exception f) {
  1298. f.printStackTrace();
  1299. }
  1300.  
  1301.  
  1302.  
  1303.  
  1304. }while(categoryCheck == false);
  1305.  
  1306.  
  1307.  
  1308. }else {
  1309. e.text(ebay.getCategoryId());
  1310.  
  1311. }
  1312.  
  1313.  
  1314. //pics
  1315. e = xmlDoc.select("PictureDetails").first();
  1316. e.text("");
  1317.  
  1318. boolean isImgfirstPhoto = true;
  1319.  
  1320. int x = 0;
  1321.  
  1322. for(String imgUrl: amzn.getAmazonHighResImgList())
  1323. {
  1324. try {
  1325. System.out.println(imgUrl);
  1326. System.out.println("Amazon Original Title: "+amzn.getAmazonTitle());
  1327. String ebayPictureTitle = EbayAssitivePackage.EbayTitleBuilder.titleBuilder(amzn);
  1328. System.out.println("ebayPictureTitle: "+ebayPictureTitle);
  1329. String ebayPictureUrl = "";
  1330.  
  1331. int retries = 0;
  1332. do
  1333. {
  1334. try {
  1335. ebayPictureUrl = EbayApi.UploadSiteHostedPictures(imgUrl, ebayPictureTitle, isImgfirstPhoto);
  1336. retries = 3;
  1337.  
  1338.  
  1339. }catch(Exception f)
  1340. {
  1341. f.printStackTrace();
  1342.  
  1343. }
  1344.  
  1345. retries++;
  1346.  
  1347. }while(retries < 3);
  1348.  
  1349.  
  1350. if(ebayPictureUrl.contains("ebay"))
  1351. {
  1352. e.appendElement("PictureURL").text(ebayPictureUrl);
  1353. x++;
  1354. }
  1355.  
  1356.  
  1357.  
  1358. isImgfirstPhoto = false;
  1359.  
  1360. }catch(Exception f) {
  1361. f.printStackTrace();
  1362. }
  1363.  
  1364.  
  1365. if(x==12)
  1366. {
  1367. break;
  1368. }
  1369.  
  1370. }
  1371.  
  1372.  
  1373. //Price
  1374.  
  1375. double setFixedPrice = ebay.getEbayPrice() - 0.07;;
  1376. setFixedPrice = (double) Math.round(setFixedPrice * 100) / 100;
  1377.  
  1378. e = xmlDoc.select("StartPrice").first();
  1379. e.text(Double.toString(setFixedPrice));
  1380.  
  1381.  
  1382. e = xmlDoc.select("SKU").first();
  1383. e.text(amzn.getSku());
  1384.  
  1385.  
  1386. e = xmlDoc.select("BrandMPN").first();
  1387. e.appendElement("Brand").text(amzn.getAmazonBrand());
  1388. e.appendElement("MPN").text(amzn.getAmazonMpn());
  1389.  
  1390. //NameValueList
  1391. //ItemSpecifics
  1392. e = xmlDoc.select("ItemSpecifics").first();
  1393. Map<String,String> amazonNameValueMap = amzn.getAmazonNameValueMap();
  1394. Map<String, String> reversedMap = new TreeMap<String, String>(amazonNameValueMap);
  1395.  
  1396. for(int i = 0;i<reversedMap.size();i++) {
  1397. e.appendElement("NameValueList");
  1398. }
  1399.  
  1400.  
  1401. int i = 0;
  1402. for (Map.Entry entry : reversedMap.entrySet()) {
  1403. Element nameValueList = e.child(i);
  1404.  
  1405. String name = entry.getKey().toString();
  1406. try {
  1407. name = name.substring(0, 64);
  1408. }catch(Exception f) {
  1409. f.printStackTrace();
  1410. }
  1411.  
  1412. String value = entry.getValue().toString();
  1413.  
  1414. try {
  1415. value = value.substring(0, 64);
  1416. }catch(Exception f) {
  1417. //f.printStackTrace();
  1418. }
  1419.  
  1420.  
  1421.  
  1422. nameValueList.appendElement("Name").text(name);
  1423. nameValueList.appendElement("Value").text(value);
  1424. i++;
  1425. }
  1426.  
  1427. e.appendElement("NameValueList");
  1428. Element nameValueList = e.child(i);
  1429. nameValueList.appendElement("Name").text("Brand");
  1430. nameValueList.appendElement("Value").text(amzn.getAmazonBrand());
  1431. i++;
  1432.  
  1433. e.appendElement("NameValueList");
  1434. nameValueList = e.child(i);
  1435. nameValueList.appendElement("Name").text("MPN");
  1436. nameValueList.appendElement("Value").text(amzn.getAmazonMpn());
  1437.  
  1438. i++;
  1439. e.appendElement("NameValueList");
  1440. nameValueList = e.child(i);
  1441. nameValueList.appendElement("Name").text("Model");
  1442. nameValueList.appendElement("Value").text(amzn.getAmazonMpn());
  1443.  
  1444.  
  1445. //StartPrice
  1446.  
  1447. //ProductListingDetails
  1448. e = xmlDoc.select("ProductListingDetails").first();
  1449. e.appendElement("UPC").text(ebay.getEbayUpc());
  1450.  
  1451.  
  1452.  
  1453. //System.out.println("------------------------------------------------------------------------------\n\n");
  1454. //System.out.println(xmlDoc);
  1455. //System.out.println("------------------------------------------------------------------------------\n\n");
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461. //--------------------------- Post XML -----------------------------
  1462.  
  1463.  
  1464.  
  1465. Response ebayRes =
  1466. Jsoup.connect("https://api.ebay.com/ws/api.dll") //https://api.ebay.com/ws/api.dll
  1467. .ignoreContentType(true)
  1468. .ignoreHttpErrors(true)
  1469.  
  1470.  
  1471. .header("Content-type", "text/xml")
  1472. .header("X-EBAY-API-COMPATIBILITY-LEVEL", "911")
  1473. .header("X-EBAY-API-SITEID", "2")
  1474. .header("X-EBAY-API-CALL-NAME", "AddFixedPriceItem")
  1475. .header("X-EBAY-API-APP-NAME", "TehseenA-hockeygr-PRD-8ea920fd0-0ada6f57")
  1476. .header("X-EBAY-API-CERT-NAME", "PRD-ea920fd07393-3735-4b13-8fe1-ade8")
  1477. .header("X-EBAY-API-DEV-NAME", "d58b693b-cfd5-4515-9b7d-e1432bbfb7d7")
  1478. .requestBody(xmlDoc.toString())
  1479.  
  1480. .method(Method.POST)
  1481. .execute()
  1482. ;
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490. Document ebayDoc = ebayRes.parse();
  1491. ebayDoc.outputSettings().indentAmount(3).prettyPrint(true);
  1492. ebayLink = "https://www.ebay.ca/itm/"+ebayDoc.select("ItemId").text();
  1493.  
  1494. //System.out.println(ebayDoc);
  1495.  
  1496. //System.out.println("\n\nSucessfully Listed: "+ebayLink+"\n");
  1497.  
  1498.  
  1499. ackMessage = ebayDoc.select("Ack").text();
  1500. Document ebayDocRetry = null;
  1501. Document xmlDocumentToRetry = null;
  1502.  
  1503. if(ackMessage.toLowerCase().equals("failure"))
  1504. {
  1505. xmlDocumentToRetry = RelistXmlFunction.retryXml(ebayDoc.toString(), xmlDoc.toString());
  1506.  
  1507.  
  1508. Response ResponseToRetry =
  1509. Jsoup.connect("https://api.ebay.com/ws/api.dll") //https://api.ebay.com/ws/api.dll
  1510. .ignoreContentType(true)
  1511. .ignoreHttpErrors(true)
  1512.  
  1513.  
  1514. .header("Content-type", "text/xml")
  1515. .header("X-EBAY-API-COMPATIBILITY-LEVEL", "911")
  1516. .header("X-EBAY-API-SITEID", "2")
  1517. .header("X-EBAY-API-CALL-NAME", "AddFixedPriceItem")
  1518. .header("X-EBAY-API-APP-NAME", "TehseenA-hockeygr-PRD-8ea920fd0-0ada6f57")
  1519. .header("X-EBAY-API-CERT-NAME", "PRD-ea920fd07393-3735-4b13-8fe1-ade8")
  1520. .header("X-EBAY-API-DEV-NAME", "d58b693b-cfd5-4515-9b7d-e1432bbfb7d7")
  1521. .requestBody(xmlDocumentToRetry.toString())
  1522.  
  1523. .method(Method.POST)
  1524. .execute()
  1525. ;
  1526.  
  1527.  
  1528. ebayDocRetry = ResponseToRetry.parse();
  1529. ackMessage = ebayDocRetry.select("Ack").text();
  1530.  
  1531. ebayLink = "https://www.ebay.ca/itm/"+ebayDocRetry.select("ItemId").text();
  1532.  
  1533. System.out.println(ebayDocRetry);
  1534.  
  1535.  
  1536. }
  1537.  
  1538.  
  1539.  
  1540. if(ackMessage.toLowerCase().equals("failure"))
  1541. {
  1542. Document xmlDocumentToRetry2 = RelistXmlFunction.retryXml(ebayDocRetry.toString(), xmlDocumentToRetry.toString());
  1543.  
  1544.  
  1545. Response ResponseToRetry2 =
  1546. Jsoup.connect("https://api.ebay.com/ws/api.dll") //https://api.ebay.com/ws/api.dll
  1547. .ignoreContentType(true)
  1548. .ignoreHttpErrors(true)
  1549.  
  1550.  
  1551. .header("Content-type", "text/xml")
  1552. .header("X-EBAY-API-COMPATIBILITY-LEVEL", "911")
  1553. .header("X-EBAY-API-SITEID", "2")
  1554. .header("X-EBAY-API-CALL-NAME", "AddFixedPriceItem")
  1555. .header("X-EBAY-API-APP-NAME", "TehseenA-hockeygr-PRD-8ea920fd0-0ada6f57")
  1556. .header("X-EBAY-API-CERT-NAME", "PRD-ea920fd07393-3735-4b13-8fe1-ade8")
  1557. .header("X-EBAY-API-DEV-NAME", "d58b693b-cfd5-4515-9b7d-e1432bbfb7d7")
  1558. .requestBody(xmlDocumentToRetry2.toString())
  1559.  
  1560. .method(Method.POST)
  1561. .execute()
  1562. ;
  1563.  
  1564.  
  1565. Document ebayDocRetry2 = ResponseToRetry2.parse();
  1566. ackMessage = ebayDocRetry2.select("Ack").text();
  1567.  
  1568. ebayLink = "https://www.ebay.ca/itm/"+ebayDocRetry2.select("ItemId").text();
  1569.  
  1570. System.out.println(ebayDocRetry2);
  1571.  
  1572.  
  1573. }
  1574.  
  1575. posted = true;
  1576. //------------------------------------if(search==true) {-------------------------------***[Finish]
  1577. }
  1578. return ebayLink;
  1579.  
  1580. //-public static void main(String[] args) throws IOException, JSONException {-------------------***[Finish]
  1581. }
  1582.  
  1583.  
  1584.  
  1585.  
  1586. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement