Changeset 33978 for other-projects
- Timestamp:
- 2020-02-26T19:57:05+13:00 (4 years ago)
- Location:
- other-projects/maori-lang-detection/src/org/greenstone/atea
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/maori-lang-detection/src/org/greenstone/atea/CountryCodeCountsMapData.java
r33959 r33978 656 656 } 657 657 658 public static void openFirefox() { 659 // https://www.cyberciti.biz/faq/howto-run-firefox-from-the-command-line/ 660 String[] cmdArgs = { 661 "firefox", 662 "-P", 663 "screenshot", //profile //"-profileManager=\"screenshot\"", 664 //"--browser", 665 "--devtools" 666 }; 667 668 SafeProcess proc = new SafeProcess(cmdArgs); 669 int retVal = proc.runProcess(); 670 671 if(retVal != 0) { 672 logger.info("Process out: " + proc.getStdOutput()); 673 logger.info("Process err: " + proc.getStdError()); 674 logger.info("Screenshot process returned with: " + retVal); 675 } 676 proc = null; 677 678 /* 679 String[] tab_cmdArgs = { 680 "firefox", 681 "-new-tab", 682 "-jsconsole" 683 }; 684 proc = new SafeProcess(tab_cmdArgs); 685 retVal = proc.runProcess(); 686 */ 687 } 688 689 public String getGeoJSONMapScreenshotCommand(File outputFolder, String fileNamePrefix) { 690 // return the firefox :screenshot WEB CONSOLE command 691 // Only works from Firefox version 62 onwards 692 // https://developer.mozilla.org/en-US/docs/Tools/Taking_screenshots 693 694 String mapURL = this.getAsMapURL(); 695 696 File outputFile = new File(outputFolder + File.separator + fileNamePrefix+".png"); 697 String outputFilePath = Utility.getFilePath(outputFile); 698 699 700 // Run in web console: 701 // :screenshot --selector ".map" --file --filename "<outputPath/outputImageFile.ext>" 702 // https://developer.mozilla.org/en-US/docs/Tools/Browser_Console 703 String webConsoleCommand = ":screenshot --selector \".map\" --file --filename \"" + outputFilePath + "\""; 704 System.out.println("Run in Firefox web console's command line:"); 705 System.out.println(webConsoleCommand); 706 707 // Launch firefox in a new tab 708 // https://askubuntu.com/questions/57163/how-to-open-an-url-from-command-line-to-firefox-and-switch-to-tab 709 //https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options 710 String[] cmdArgs = { 711 "firefox", 712 //"-P", 713 //"screenshot", // which does --profileManager "screenshot" 714 //"--devtools", //"-jsconsole" opens browser console instead of web console 715 "-new-tab", 716 mapURL 717 }; 718 719 720 System.err.println(); 721 SafeProcess proc = new SafeProcess(cmdArgs); 722 723 int retVal = proc.runProcess(); 724 725 if(retVal != 0) { 726 logger.info("Process out: " + proc.getStdOutput()); 727 logger.info("Process err: " + proc.getStdError()); 728 logger.info("Screenshot process returned with: " + retVal); 729 } 730 731 return webConsoleCommand; 732 } 733 658 734 public String geoJsonMapScreenshot(File outputFolder, String fileNamePrefix) { 659 735 // https://stackoverflow.com/questions/49606051/how-to-take-a-screenshot-in-firefox-headless-selenium-in-java -
other-projects/maori-lang-detection/src/org/greenstone/atea/SummaryTool.java
r33940 r33978 356 356 */ 357 357 public static void main(String args[]) { 358 SafeProcess.DEBUG = 1; 359 358 int oldDebugMode = SafeProcess.DEBUG; 359 SafeProcess.DEBUG = 0; 360 360 361 if(args.length >= 2) { 361 362 printUsage(); … … 417 418 // that GEOJSON_MAP_TOOL_URL takes as input to produce a map. 418 419 420 ///CountryCodeCountsMapData.openFirefox(); 421 419 422 for(int i = 1; i < tableFileNames.length; i++) { // empty element at 0 420 423 String tablefilename = tableFileNames[i] + ".json"; // filenames have no suffix … … 453 456 // to confirm if the JSON in the provided json file parses/is valid JSON. 454 457 458 /* 455 459 String[] cmdArgs = {"python", "-mjson.tool", geoJsonFilename}; 456 460 SafeProcess p = new SafeProcess(cmdArgs); … … 465 469 continue; 466 470 } 467 471 */ 468 472 469 473 /*boolean uriEncoded = true; … … 472 476 */ 473 477 474 logger.info("Data URL string: " + mapData.getAsMapURL());478 //logger.info("Data URL string: " + mapData.getAsMapURL()); 475 479 logger.info(""); 476 mapData.geoJsonMapScreenshot(outFolder, tablefilename); 480 //mapData.geoJsonMapScreenshot(outFolder, tablefilename); 481 mapData.getGeoJSONMapScreenshotCommand(outFolder, tablefilename); 477 482 logger.info("---"); 478 483 479 484 // TODO: Remove break. For debugging: breaks after first table -> map conversion. 480 break;485 //break; 481 486 } 482 487 … … 486 491 } catch(Exception e) { 487 492 logger.error(e.getMessage(), e); 488 } 493 } finally { 494 SafeProcess.DEBUG = oldDebugMode; 495 } 489 496 } 490 497 }
Note:
See TracChangeset
for help on using the changeset viewer.