Changeset 33981


Ignore:
Timestamp:
2020-02-26T21:19:23+13:00 (4 years ago)
Author:
ak19
Message:

As Dr Bainbridge suggested, code now opens a new firefox tab with a subsequent geojson map after Enter pressed. Further, the firefox webconsole screenshot command is now already added to copy buffer which works on my Ubuntu.

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

    r33978 r33981  
    3737
    3838import org.greenstone.util.SafeProcess;
     39
     40// copying to clipboard
     41import java.awt.Toolkit;
     42import java.awt.datatransfer.StringSelection;
     43import java.awt.datatransfer.Clipboard;
     44
    3945
    4046/**
     
    702708    // https://developer.mozilla.org/en-US/docs/Tools/Browser_Console
    703709    String webConsoleCommand = ":screenshot --selector \".map\" --file --filename \"" + outputFilePath + "\""; 
    704     System.out.println("Run in Firefox web console's command line:");
     710    System.out.println("The following command should be copied to your clipboard. Else copy it.");
     711    System.out.println("Run it in the opened Firefox tab's Web Console command line (press F12 and undock web console first):\n");
    705712    System.out.println(webConsoleCommand);
    706    
     713    copyStringToCopyBuffer(webConsoleCommand);
     714       
    707715    // Launch firefox in a new tab
    708716    // https://askubuntu.com/questions/57163/how-to-open-an-url-from-command-line-to-firefox-and-switch-to-tab
     
    727735        logger.info("Process err: " + proc.getStdError());
    728736        logger.info("Screenshot process returned with: " + retVal);
    729     }
    730 
     737    }   
     738   
    731739    return webConsoleCommand;
    732740    }
    733741
     742    /** Copies string to copy buffer. Works for me in Firefox on Ubuntu.
     743     * Code from https://stackoverflow.com/questions/3591945/copying-to-the-clipboard-in-java
     744     */
     745    public void copyStringToCopyBuffer(String str) {
     746    StringSelection selection = new StringSelection(str);
     747    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
     748    clipboard.setContents(selection, selection);
     749    }
     750   
     751    // Doesn't work
    734752    public String geoJsonMapScreenshot(File outputFolder, String fileNamePrefix) {
    735753    // 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

    r33978 r33981  
    189189    if(outFile.exists()) {
    190190        logger.error("WARN: Full web page urls list file already exists: " + fullFileName);
    191         logger.error("      Will not overwrite. Delete file manually and re-run this program.");
     191        logger.error("      Will not overwrite as it may already have been processed.");
     192        logger.error("      If you're sure, rename/delete the file manually and re-run this program.");
    192193        return;
    193194    }
     
    356357     */
    357358    public static void main(String args[]) {
     359    boolean doDebug = false;
     360   
    358361    int oldDebugMode = SafeProcess.DEBUG;
    359     SafeProcess.DEBUG = 0;
     362    SafeProcess.DEBUG = doDebug ? 1 : 0;
    360363
    361364    if(args.length >= 2) {
     
    366369    try (
    367370         MongoDBQueryer mongodb = new MongoDBQueryer();
     371         BufferedReader systemIn = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
    368372         ) {
    369373
     
    397401        } else {       
    398402
    399         // calculating sample size works:
     403        // TEST: calculating sample size works:
    400404        //System.err.println("For N = " + 4360 + ", n = " + listing.calcSampleSize(4360));
    401405        //System.err.println("For N = " + 681 + ", n = " + listing.calcSampleSize(681));
     
    434438            String geoJsonFilename = mapData.writeFeaturesGeoJsonToFile(CountryCodeCountsMapData.SUPPRESS_MAPDATA_DISPLAY);
    435439           
    436 
    437             /*
    438             // Ensure the geo-json file generated exists
     440            // Ensuring the geo-json file generated exists
    439441            //String geoJsonFilename = outFolder + File.separator
    440             //+ GEOJSON_FEATURES_FILE_PREFIX + tablefilename;
    441            
     442            //+ GEOJSON_FEATURES_FILE_PREFIX + tablefilename;           
    442443            File geoJsonFile = new File(geoJsonFilename);
    443444            if(!geoJsonFile.exists()) {
    444445            logger.info("@@@ geoJson file " + geoJsonFilename + " not generated!");
    445             continue;
    446             }
    447             */
    448             logger.info("**** Wrote mapdata to file " + geoJsonFilename);
    449             //logger.info("     Paste the file's geojson contents into "
    450             //+ "the editor at " + CountryCodeCountsMapData.GEOJSON_MAP_TOOL_URL
    451             //+ " to see the data arranged on a world map");           
    452             logger.info("Total count for query: " + mapData.getTotalCount());
     446            //continue;
     447            }
     448            else {
     449            if(doDebug) {
     450                logger.info("**** Wrote mapdata to file " + geoJsonFilename);
     451                //logger.info("     Paste the file's geojson contents into "
     452                //+ "the editor at " + CountryCodeCountsMapData.GEOJSON_MAP_TOOL_URL
     453                //+ " to see the data arranged on a world map");
     454                logger.info("Total count for query: " + mapData.getTotalCount());
     455            }
     456            }           
     457           
    453458           
    454459            // Running the command:
     
    456461            // to confirm if the JSON in the provided json file parses/is valid JSON.
    457462
    458             /*
     463           
    459464            String[] cmdArgs = {"python", "-mjson.tool", geoJsonFilename};
    460465            SafeProcess p = new SafeProcess(cmdArgs);
    461466            int retVal = p.runProcess();
    462             logger.info("\nJson validation tool returned with value: " + retVal);
    463             if(retVal == 0) {
    464             logger.info("Valid geo json.");
    465             } else {
     467
     468            if(retVal != 0) {
     469            logger.info("\nJson validation tool returned with value: " + retVal);
    466470            logger.error("   std out: " + p.getStdOutput());
    467471            logger.error("   std err: " + p.getStdError());
    468472            logger.error("INVALID geo json generated. Not attempting screenshot of map.");
     473            logger.info("");
    469474            continue;
    470475            }
    471             */
    472            
    473             /*boolean uriEncoded = true;
    474             String mapDataEncodedStr = mapData.getFeaturesGeoJsonString(uriEncoded);
    475             logger.info("Encoded string: " + mapDataEncodedStr);
    476             */
     476           
    477477           
    478478            //logger.info("Data URL string: " + mapData.getAsMapURL());
    479479            logger.info("");
    480480            //mapData.geoJsonMapScreenshot(outFolder, tablefilename);
    481             mapData.getGeoJSONMapScreenshotCommand(outFolder, tablefilename);
     481            mapData.getGeoJSONMapScreenshotCommand(outFolder, tablefilename.replace(".json", ""));
    482482            logger.info("---");
    483483
     484
     485            System.out.println("Press Enter to continue >");
     486            String userEntered = "";
     487            while((userEntered = systemIn.readLine()) != null) {
     488            if(userEntered.equals("")) { // line read and empty
     489                break;
     490            }
     491            else {                         
     492                System.out.println("Press Enter to continue >");
     493            }
     494            }
     495           
    484496            // TODO: Remove break. For debugging: breaks after first table -> map conversion.
    485497            //break;
Note: See TracChangeset for help on using the changeset viewer.