cn.hutool.log.StaticLog Java Examples

The following examples show how to use cn.hutool.log.StaticLog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CityStats.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
public static void parseCity(String url, Area provinceArea) {
    String htmlStr = HttpUtil.get(url, CHARSET);
    Document document = Jsoup.parse(htmlStr);
    Elements trs = document.getElementsByClass("citytr");
    List<Area> cities = new LinkedList<Area>();
    int sort = 1;
    for (Element tr : trs) {
        Elements links = tr.getElementsByTag("a");
        String href = links.get(0).attr("href");
        String cityCode = links.get(0).text().substring(0, 4);
        String cityName = links.get(1).text();

        Area cityArea = Area.builder().label(cityName).code(cityCode).source(url)
                .sortValue(sort++).level(new RemoteData<>("CITY")).fullName(provinceArea.getFullName() + cityName)
                .build();

        StaticLog.info("	市级数据:  {}  ", cityArea);

        parseCounty(COMMON_URL + href, cityArea);
        cities.add(cityArea);
    }
    provinceArea.setChildren(cities);
}
 
Example #2
Source File: CityStats.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
public static void parseCity(String url, Area provinceArea) {
    String htmlStr = HttpUtil.get(url, CHARSET);
    Document document = Jsoup.parse(htmlStr);
    Elements trs = document.getElementsByClass("citytr");
    List<Area> cities = new LinkedList<Area>();
    int sort = 1;
    for (Element tr : trs) {
        Elements links = tr.getElementsByTag("a");
        String href = links.get(0).attr("href");
        String cityCode = links.get(0).text().substring(0, 4);
        String cityName = links.get(1).text();

        Area cityArea = Area.builder().label(cityName).code(cityCode).source(url)
                .sortValue(sort++).level(new RemoteData<>("CITY")).fullName(provinceArea.getFullName() + cityName)
                .build();

        StaticLog.info("	市级数据:  {}  ", cityArea);

        parseCounty(COMMON_URL + href, cityArea);
        cities.add(cityArea);
    }
    provinceArea.setChildren(cities);
}
 
Example #3
Source File: CityStats.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
public static void parseCounty(String url, Area cityArea) {
    String htmlStr = HttpUtil.get(url, CHARSET);
    Document document = Jsoup.parse(htmlStr);
    Elements trs = document.getElementsByClass("countytr");
    List<Area> counties = new LinkedList<Area>();
    int sort = 1;
    for (Element tr : trs) {
        Elements links = tr.getElementsByTag("a");
        if (links == null || links.size() != 2) {
            continue;
        }
        String href = links.get(0).attr("href");
        String countyCode = links.get(0).text().substring(0, 6);
        String countyName = links.get(1).text();

        Area countyArea = Area.builder().label(countyName).code(countyCode).source(url)
                .sortValue(sort++).level(new RemoteData<>("COUNTY")).fullName(cityArea.getFullName() + countyName)
                .build();

        StaticLog.info("		县级数据:  {}  ", countyArea);

        parseTowntr(COMMON_URL + href.subSequence(2, 5).toString() + "/" + href, countyArea);
        counties.add(cityArea);
    }
    cityArea.setChildren(counties);
}
 
Example #4
Source File: TestResource.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void testDozerAndBean() {

    //10000 - 688
    //50000 - 2130
    //100000 - 4050  2438
    //1000000 - 22085   20375

    // 放弃理由

    TimeInterval timer = DateUtil.timer();
    for (int i = 0; i <= 1000000; i++) {
        Org org = Org.builder()
                .label("string")
                .id(123L + i)
                .createTime(LocalDateTime.now())
                .build();
        Station station = Station.builder().id(1L + i).name("nihaoa").createTime(LocalDateTime.now()).orgId(new RemoteData(12L, org)).build();

        StationPageDTO stationPageDTO = dozer.map(station, StationPageDTO.class);
    }

    long interval = timer.interval();// 花费毫秒数
    long intervalMinute = timer.intervalMinute();// 花费分钟数
    StaticLog.info("本次程序执行 花费毫秒数: {} ,   花费分钟数:{} . ", interval, intervalMinute);
}
 
Example #5
Source File: NoBootTest.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void testBeanUtil() {

    //10000 - 511
    //50000 - 719
    //100000 - 812
    //1000000 - 2303

    TimeInterval timer = DateUtil.timer();
    for (int i = 0; i <= 1000000; i++) {
        Org org = Org.builder()
                .label("string")
                .id(123L + i)
                .createTime(LocalDateTime.now())
                .build();
        Station station = Station.builder().id(1L + i).name("nihaoa").createTime(LocalDateTime.now()).orgId(new RemoteData(12L, org)).build();

        StationPageDTO stationPageDTO = new StationPageDTO();

        BeanUtil.copyProperties(station, stationPageDTO);
    }

    long interval = timer.interval();// 花费毫秒数
    long intervalMinute = timer.intervalMinute();// 花费分钟数
    StaticLog.info("本次程序执行 花费毫秒数: {} ,   花费分钟数:{} . ", interval, intervalMinute);
}
 
Example #6
Source File: CityStats.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
public static void parseVillagetr(String url, Area countyArea) {
    String htmlStr = HttpUtil.get(url, CHARSET);
    Document document = Jsoup.parse(htmlStr);
    Elements trs = document.getElementsByClass("villagetr");

    List<Area> counties = new LinkedList<Area>();
    int sort = 1;
    for (Element tr : trs) {
        Elements tds = tr.getElementsByTag("td");
        if (tds == null || tds.size() != 3) {
            continue;
        }
        String villagetrCode = tds.get(0).text();
        String villagetrName = tds.get(2).text();

        Area villagetrArea = Area.builder().code(villagetrCode).label(villagetrName).source(url)
                .sortValue(sort++).level(new RemoteData<>("VILLAGETR")).fullName(countyArea.getFullName() + villagetrName)
                .build();
        StaticLog.info("		村级数据:  {}  ", villagetrArea);

        counties.add(villagetrArea);

    }
    countyArea.setChildren(counties);
}
 
Example #7
Source File: CityParser.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
private List<Area> parseCity(String provinceName, String url) {
        String htmlStr = HttpUtil.get(url, CHARSET);
        Document document = Jsoup.parse(htmlStr);
        Elements trs = document.getElementsByClass("citytr");

        List<Area> cities = new LinkedList<Area>();
        int sort = 1;
        for (Element tr : trs) {
            Elements links = tr.getElementsByTag("a");
            String href = links.get(0).attr("href");
            String cityCode = links.get(0).text();
//            String cityCode = links.get(0).text().substring(0, 4);
            String cityName = links.get(1).text();

            Area cityArea = Area.builder()
                    .label(cityName).code(cityCode).source(url).sortValue(sort++)
                    .level(new RemoteData<>("CITY"))
                    .fullName(provinceName + cityName)
                    .build();
            cityArea.setChildren(parseCounty(provinceName + cityName, COMMON_URL + href));
            StaticLog.info("	市级数据:  {}  ", cityArea);

            cities.add(cityArea);
        }
        return cities;
    }
 
Example #8
Source File: CityParser.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
private List<Area> parseCity(String provinceName, String url) {
        String htmlStr = HttpUtil.get(url, CHARSET);
        Document document = Jsoup.parse(htmlStr);
        Elements trs = document.getElementsByClass("citytr");

        List<Area> cities = new LinkedList<Area>();
        int sort = 1;
        for (Element tr : trs) {
            Elements links = tr.getElementsByTag("a");
            String href = links.get(0).attr("href");
            String cityCode = links.get(0).text();
//            String cityCode = links.get(0).text().substring(0, 4);
            String cityName = links.get(1).text();

            Area cityArea = Area.builder()
                    .label(cityName).code(cityCode).source(url).sortValue(sort++)
                    .level(new RemoteData<>("CITY"))
                    .fullName(provinceName + cityName)
                    .build();
            cityArea.setChildren(parseCounty(provinceName + cityName, COMMON_URL + href));
            StaticLog.info("	市级数据:  {}  ", cityArea);

            cities.add(cityArea);
        }
        return cities;
    }
 
Example #9
Source File: CityStats.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
public static void parseVillagetr(String url, Area countyArea) {
    String htmlStr = HttpUtil.get(url, CHARSET);
    Document document = Jsoup.parse(htmlStr);
    Elements trs = document.getElementsByClass("villagetr");

    List<Area> counties = new LinkedList<Area>();
    int sort = 1;
    for (Element tr : trs) {
        Elements tds = tr.getElementsByTag("td");
        if (tds == null || tds.size() != 3) {
            continue;
        }
        String villagetrCode = tds.get(0).text();
        String villagetrName = tds.get(2).text();

        Area villagetrArea = Area.builder().code(villagetrCode).label(villagetrName).source(url)
                .sortValue(sort++).level(new RemoteData<>("VILLAGETR")).fullName(countyArea.getFullName() + villagetrName)
                .build();
        StaticLog.info("		村级数据:  {}  ", villagetrArea);

        counties.add(villagetrArea);

    }
    countyArea.setChildren(counties);
}
 
Example #10
Source File: CityStats.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
public static void parseCounty(String url, Area cityArea) {
    String htmlStr = HttpUtil.get(url, CHARSET);
    Document document = Jsoup.parse(htmlStr);
    Elements trs = document.getElementsByClass("countytr");
    List<Area> counties = new LinkedList<Area>();
    int sort = 1;
    for (Element tr : trs) {
        Elements links = tr.getElementsByTag("a");
        if (links == null || links.size() != 2) {
            continue;
        }
        String href = links.get(0).attr("href");
        String countyCode = links.get(0).text().substring(0, 6);
        String countyName = links.get(1).text();

        Area countyArea = Area.builder().label(countyName).code(countyCode).source(url)
                .sortValue(sort++).level(new RemoteData<>("COUNTY")).fullName(cityArea.getFullName() + countyName)
                .build();

        StaticLog.info("		县级数据:  {}  ", countyArea);

        parseTowntr(COMMON_URL + href.subSequence(2, 5).toString() + "/" + href, countyArea);
        counties.add(cityArea);
    }
    cityArea.setChildren(counties);
}
 
Example #11
Source File: NoBootTest.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@Test
public void testBeanUtil() {

    //10000 - 511
    //50000 - 719
    //100000 - 812
    //1000000 - 2303

    TimeInterval timer = DateUtil.timer();
    for (int i = 0; i <= 1000000; i++) {
        Org org = Org.builder()
                .label("string")
                .id(123L + i)
                .createTime(LocalDateTime.now())
                .build();
        Station station = Station.builder().id(1L + i).name("nihaoa").createTime(LocalDateTime.now()).orgId(new RemoteData(12L, org)).build();

        StationPageDTO stationPageDTO = new StationPageDTO();

        BeanUtil.copyProperties(station, stationPageDTO);
    }

    long interval = timer.interval();// 花费毫秒数
    long intervalMinute = timer.intervalMinute();// 花费分钟数
    StaticLog.info("本次程序执行 花费毫秒数: {} ,   花费分钟数:{} . ", interval, intervalMinute);
}
 
Example #12
Source File: TestResource.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@Test
public void testDozerAndBean() {

    //10000 - 688
    //50000 - 2130
    //100000 - 4050  2438
    //1000000 - 22085   20375

    // 放弃理由

    TimeInterval timer = DateUtil.timer();
    for (int i = 0; i <= 1000000; i++) {
        Org org = Org.builder()
                .label("string")
                .id(123L + i)
                .createTime(LocalDateTime.now())
                .build();
        Station station = Station.builder().id(1L + i).name("nihaoa").createTime(LocalDateTime.now()).orgId(new RemoteData(12L, org)).build();

        StationPageDTO stationPageDTO = dozer.map(station, StationPageDTO.class);
    }

    long interval = timer.interval();// 花费毫秒数
    long intervalMinute = timer.intervalMinute();// 花费分钟数
    StaticLog.info("本次程序执行 花费毫秒数: {} ,   花费分钟数:{} . ", interval, intervalMinute);
}
 
Example #13
Source File: MainFm.java    From tools-ocr with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void recImage() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Please Select Image File");
    fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Image Files", "*.png", "*.jpg"));
    File selectedFile = fileChooser.showOpenDialog(stage);
    if (selectedFile == null || !selectedFile.isFile()) {
        return;
    }
    stageInfo = new StageInfo(stage.getX(), stage.getY(),
            stage.getWidth(), stage.getHeight(), stage.isFullScreen());
    MainFm.stage.close();
    try {
        BufferedImage image = ImageIO.read(selectedFile);
        doOcr(image);
    } catch (IOException e) {
        StaticLog.error(e);
    }
}
 
Example #14
Source File: CommUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void initStage(Stage stage) {
    try {
        if (CommUtils.IS_MAC_OS) {
            URL iconURL = MainFm.class.getResource("/img/logo.png");
            java.awt.Image image = new ImageIcon(iconURL).getImage();
            Class appleApp = Class.forName("com.apple.eawt.Application");
            //noinspection unchecked
            Method getApplication = appleApp.getMethod("getApplication");
            Object application = getApplication.invoke(appleApp);
            Class[] params = new Class[1];
            params[0] = java.awt.Image.class;
            //noinspection unchecked
            Method setDockIconImage = appleApp.getMethod("setDockIconImage", params);
            setDockIconImage.invoke(application, image);
        }
    } catch (Exception e) {
        StaticLog.error(e);
    }
    stage.setTitle("树洞OCR文字识别");
    stage.getIcons().add(new javafx.scene.image.Image(MainFm.class.getResource("/img/logo.png").toExternalForm()));
}
 
Example #15
Source File: CommUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static String postMultiData(String url, byte[] data, String boundary, String cookie, String referer) {
    try {
        HttpRequest request = HttpUtil.createPost(url).timeout(15000);
        request.contentType("multipart/form-data; boundary=" + boundary);
        request.body(data);
        if (StrUtil.isNotBlank(referer)) {
            request.header("Referer", referer);
        }
        if (StrUtil.isNotBlank(cookie)) {
            request.cookie(cookie);
        }
        HttpResponse response = request.execute();
        return WebUtils.getSafeHtml(response);
    } catch (Exception ex) {
        StaticLog.error(ex);
        return null;
    }
}
 
Example #16
Source File: CommUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static byte[] imageToBytes(BufferedImage img) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    MemoryCacheImageOutputStream outputStream = new MemoryCacheImageOutputStream(byteArrayOutputStream);
    try {
        Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
        ImageWriter writer = (ImageWriter) iter.next();
        ImageWriteParam iwp = writer.getDefaultWriteParam();
        iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        iwp.setCompressionQuality(IMAGE_QUALITY);
        writer.setOutput(outputStream);
        IIOImage image = new IIOImage(img, null, null);
        writer.write(null, image, iwp);
        writer.dispose();
        byte[] result = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.close();
        outputStream.close();
        return result;
    } catch (IOException e) {
        StaticLog.error(e);
        return new byte[0];
    }
}
 
Example #17
Source File: CityParser.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 村庄数据
 *
 * @param url
 * @return
 */
public List<Area> parseVillagetr(String fullName, String url) {
    String htmlStr = HttpUtil.get(url, CHARSET);
    Document document = Jsoup.parse(htmlStr);
    Elements trs = document.getElementsByClass("villagetr");

    List<Area> counties = new LinkedList<Area>();
    int sort = 1;
    for (Element tr : trs) {
        Elements tds = tr.getElementsByTag("td");
        if (tds == null || tds.size() != 3) {
            continue;
        }
        String villagetrCode = tds.get(0).text();
        String villagetrName = tds.get(2).text();

        Area villagetrArea = Area.builder().code(villagetrCode)
                .label(villagetrName)
                .fullName(fullName + villagetrName)
                .sortValue(sort++)
                .source(url).build();
        StaticLog.info("				村级数据:  {}  ", villagetrArea);

        counties.add(villagetrArea);
    }
    return counties;
}
 
Example #18
Source File: CityParser.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
/**
     * 乡镇级数据
     *
     * @param url
     * @return
     */
    public List<Area> parseTowntr(String fullName, String url) {
        String htmlStr = HttpUtil.get(url, CHARSET);
        Document document = Jsoup.parse(htmlStr);
        Elements trs = document.getElementsByClass("towntr");

        List<Area> counties = new LinkedList<Area>();
        int sort = 1;
        for (Element tr : trs) {
            Elements links = tr.getElementsByTag("a");
            if (links == null || links.size() != 2) {
                continue;
            }
            String href = links.get(0).attr("href");
            String towntrCode = links.get(0).text();
//            String towntrCode = links.get(0).text().substring(0, 6);
            String towntrName = links.get(1).text();

            Area towntrArea = Area.builder()
                    .label(towntrName).code(towntrCode).source(url)
                    .fullName(fullName + towntrName)
                    .level(new RemoteData<>("TOWNTR"))
                    .sortValue(sort++)
//                    .nodes(parseVillagetr(fullName + towntrName, COMMON_URL + href.subSequence(2, 5).toString() + "/" + href.substring(5, 7) + "/" + href))
                    .build();

            StaticLog.info("			乡镇级数据:  {}  ", towntrArea);

            counties.add(towntrArea);
        }
        return counties;
    }
 
Example #19
Source File: DocumentBrowser.java    From book118-downloader with MIT License 5 votes vote down vote up
/**
 * 下载文件到本地
 *
 * @param url       文件的 url
 * @param localPath 本地存储路径
 */
private void downloadFile(String url, String localPath) {
    File file = new File(localPath);
    try (FileOutputStream fileOutputStream = new FileOutputStream(file); BufferedOutputStream out = new BufferedOutputStream(fileOutputStream)) {
        HttpUtil.download(url, out, true);
    } catch (IOException e) {
        StaticLog.error(e.getMessage());
    }
}
 
Example #20
Source File: CityParser.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
private List<Area> parseCounty(String fullName, String url) {
        String htmlStr = HttpUtil.get(url, CHARSET);
        Document document = Jsoup.parse(htmlStr);
        Elements trs = document.getElementsByClass("countytr");

        List<Area> counties = new LinkedList<Area>();
        int sort = 1;
        for (Element tr : trs) {
            Elements links = tr.getElementsByTag("a");
            if (links == null || links.size() != 2) {
                continue;
            }
            String href = links.get(0).attr("href");
            String countyCode = links.get(0).text();
//            String countyCode = links.get(0).text().substring(0, 6);
            String countyName = links.get(1).text();

            Area countyArea = Area.builder().code(countyCode)
                    .label(countyName)
                    .source(url)
                    .fullName(fullName + countyName)
                    .sortValue(sort++)
                    .level(new RemoteData<>("COUNTY"))
//                    .nodes(parseTowntr(fullName + countyName, COMMON_URL + href.subSequence(2, 5).toString() + "/" + href))
                    .build();
            StaticLog.info("		县级数据:  {}  ", countyArea);

            counties.add(countyArea);
        }
        return counties;
    }
 
Example #21
Source File: DocumentBrowser.java    From book118-downloader with MIT License 5 votes vote down vote up
private String moveToNextPage(PdfInfo pInfo) {
    String sNextPage = getNextPage(pInfo);
    try {
        pInfo.setImg(URLEncoder.encode(sNextPage, "utf8"));
    } catch (Exception e) {
        StaticLog.error("moveToNextPage error", e);
    }
    return sNextPage;
}
 
Example #22
Source File: CityParser.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
private List<Area> parseProvince(String url) {

        String htmlStr = HttpUtil.get(url, CHARSET);
        Document document = Jsoup.parse(htmlStr);

        // 获取 class='provincetr' 的元素
        Elements elements = document.getElementsByClass("provincetr");
        List<Area> provinces = new LinkedList<Area>();
        int sort = 1;
        for (Element element : elements) {
            // 获取 elements 下属性是 href 的元素
            Elements links = element.getElementsByAttribute("href");
            for (Element link : links) {
                String provinceName = link.text();
                String href = link.attr("href");
                String provinceCode = href.substring(0, 2);

                Area provinceArea = Area.builder().code(provinceCode + "0000")
                        .label(provinceName).source(url)
                        .sortValue(sort++)
                        .level(new RemoteData<>("PROVINCE"))
                        .fullName(provinceName)
                        .build();
                provinceArea.setChildren(parseCity(provinceName, COMMON_URL + href));

                StaticLog.info("省级数据:  {}  ", provinceArea);

                provinces.add(provinceArea);
            }
        }
        return provinces;
    }
 
Example #23
Source File: DocumentBrowser.java    From book118-downloader with MIT License 5 votes vote down vote up
/**
 *  下载文档的全部图片
 *
 * @param documentId 文档编号
 * @throws IOException       pdf创建错误
 * @throws DocumentException pdf创建错误
 */
void downloadWholeDocument(String documentId) throws IOException, DocumentException {
    String srcPath = TEMP_PATH + "/" + documentId;
    FileUtil.mkdir(new File(srcPath));
    FileUtil.mkdir(new File(DES_PATH));

    int page = 1, nDownloadedPage;
    // 断点下载
    nDownloadedPage = readDownloadedPage(documentId);
    if (nDownloadedPage != 1) {
        System.out.println(String.format("下载继续,当前已完成 %d 页", nDownloadedPage));
        nDownloadedPage ++;
    }
    StringBuilder currentDownPage = new StringBuilder();
    PdfInfo pdfInfo = getPdfInfo(documentId);
    String imgUrl;
    StaticLog.info("\n开始下载...");
    while (pdfInfo != null) {
        String nextPage = moveToNextPage(pdfInfo);
        if (!Constants.TAG_OF_END.contains(nextPage)) {
            //跳过已下载的文件
            if (page < nDownloadedPage) {
                System.out.print(String.format("\r当前页码: [%d]  已跳过", page));
                page ++; continue;
            }
            imgUrl = (pdfInfo.getHost() + Constants.IMG_PREFIX_URL + nextPage);
            downloadFile(imgUrl, srcPath + "/" + autoGenericCode(page, Constants.MAX_BIT_OF_PAGE) + ".gif");
            currentDownPage.append("\r").append(String.format("已下载页数:[%d] 页", page));
            System.out.print(currentDownPage);
            // 保存当前下载完成页码
            writeDownloadedPage(documentId, page);
            page++;
        } else {
            break;
        }
    }
    StaticLog.info("\n开始生成...");
    PdfGenerator.creatPDF(srcPath, DES_PATH + "/" + documentId + ".pdf", "gif");
    FileUtil.del(new File(srcPath));
}
 
Example #24
Source File: CityStats.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
public static void parseTowntr(String url, Area countyArea) {
    String htmlStr = HttpUtil.get(url, CHARSET);
    Document document = Jsoup.parse(htmlStr);
    Elements trs = document.getElementsByClass("towntr");

    List<Area> counties = new LinkedList<Area>();
    int sort = 1;
    for (Element tr : trs) {
        Elements links = tr.getElementsByTag("a");
        if (links == null || links.size() != 2) {
            continue;
        }
        String href = links.get(0).attr("href");
        String towntrCode = links.get(0).text().substring(0, 9);
        String towntrName = links.get(1).text();

        Area towntrArea = Area.builder().label(towntrName).code(towntrCode).source(url)
                .sortValue(sort++).level(new RemoteData<>("TOWNTR")).fullName(countyArea.getFullName() + towntrName)
                .build();

        StaticLog.info("		乡镇级数据:  {}  ", towntrArea);

        parseVillagetr(COMMON_URL + href.subSequence(2, 5).toString() + "/" + href.substring(5, 7) + "/" + href,
                countyArea);

        counties.add(towntrArea);
    }
    countyArea.setChildren(counties);
}
 
Example #25
Source File: OcrUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String ocrImg(byte[] imgData) {
    int i = Math.abs(UUID.randomUUID().hashCode()) % 4;
    StaticLog.info("OCR Engine: " + i);
    switch (i){
        case 0:
            return bdGeneralOcr(imgData);
        case 1:
            return bdAccurateOcr(imgData);
        case 2:
            return sogouMobileOcr(imgData);
        default:
            return sogouWebOcr(imgData);
    }
}
 
Example #26
Source File: CityStats.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
public static void parseProvince(String url) {

        String htmlStr = HttpUtil.get(url, CHARSET);

        Document document = Jsoup.parse(htmlStr);

        // 获取 class='provincetr' 的元素
        Elements elements = document.getElementsByClass("provincetr");
        List<Area> provinces = new LinkedList<Area>();
        int sort = 1;
        for (Element element : elements) {
            // 获取 elements 下属性是 href 的元素
            Elements links = element.getElementsByAttribute("href");
            for (Element link : links) {
                String provinceName = link.text();
                String href = link.attr("href");
                String provinceCode = href.substring(0, 2);

                StaticLog.info("provinceName: {} , provinceCode: {} .", provinceName, provinceCode);

                Area provinceArea = Area.builder().code(provinceCode).label(provinceName).source(url)
                        .sortValue(sort++).fullName(provinceName).level(new RemoteData<>("PROVINCE"))
                        .build();

                StaticLog.info("省级数据:  {}  ", provinceArea);

                parseCity(COMMON_URL + href, provinceArea);
                provinces.add(provinceArea);
            }
        }
        StaticLog.info(JSONUtil.toJsonPrettyStr(provinces));
    }
 
Example #27
Source File: CityParserTest.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Test
public void init() {
    TimeInterval timer = DateUtil.timer();
    // -------这是执行过程--------------
    cityParserDecorator();
    // ---------------------------------
    long interval = timer.interval();// 花费毫秒数
    long intervalMinute = timer.intervalMinute();// 花费分钟数
    StaticLog.info("本次程序执行 花费毫秒数: {} ,   花费分钟数:{} . ", interval, intervalMinute);
}
 
Example #28
Source File: CityParser.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 村庄数据
 *
 * @param url
 * @return
 */
public List<Area> parseVillagetr(String fullName, String url) {
    String htmlStr = HttpUtil.get(url, CHARSET);
    Document document = Jsoup.parse(htmlStr);
    Elements trs = document.getElementsByClass("villagetr");

    List<Area> counties = new LinkedList<Area>();
    int sort = 1;
    for (Element tr : trs) {
        Elements tds = tr.getElementsByTag("td");
        if (tds == null || tds.size() != 3) {
            continue;
        }
        String villagetrCode = tds.get(0).text();
        String villagetrName = tds.get(2).text();

        Area villagetrArea = Area.builder().code(villagetrCode)
                .label(villagetrName)
                .fullName(fullName + villagetrName)
                .sortValue(sort++)
                .source(url).build();
        StaticLog.info("				村级数据:  {}  ", villagetrArea);

        counties.add(villagetrArea);
    }
    return counties;
}
 
Example #29
Source File: CityParser.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
/**
     * 乡镇级数据
     *
     * @param url
     * @return
     */
    public List<Area> parseTowntr(String fullName, String url) {
        String htmlStr = HttpUtil.get(url, CHARSET);
        Document document = Jsoup.parse(htmlStr);
        Elements trs = document.getElementsByClass("towntr");

        List<Area> counties = new LinkedList<Area>();
        int sort = 1;
        for (Element tr : trs) {
            Elements links = tr.getElementsByTag("a");
            if (links == null || links.size() != 2) {
                continue;
            }
            String href = links.get(0).attr("href");
            String towntrCode = links.get(0).text();
//            String towntrCode = links.get(0).text().substring(0, 6);
            String towntrName = links.get(1).text();

            Area towntrArea = Area.builder()
                    .label(towntrName).code(towntrCode).source(url)
                    .fullName(fullName + towntrName)
                    .level(new RemoteData<>("TOWNTR"))
                    .sortValue(sort++)
//                    .nodes(parseVillagetr(fullName + towntrName, COMMON_URL + href.subSequence(2, 5).toString() + "/" + href.substring(5, 7) + "/" + href))
                    .build();

            StaticLog.info("			乡镇级数据:  {}  ", towntrArea);

            counties.add(towntrArea);
        }
        return counties;
    }
 
Example #30
Source File: CityParser.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
private List<Area> parseCounty(String fullName, String url) {
        String htmlStr = HttpUtil.get(url, CHARSET);
        Document document = Jsoup.parse(htmlStr);
        Elements trs = document.getElementsByClass("countytr");

        List<Area> counties = new LinkedList<Area>();
        int sort = 1;
        for (Element tr : trs) {
            Elements links = tr.getElementsByTag("a");
            if (links == null || links.size() != 2) {
                continue;
            }
            String href = links.get(0).attr("href");
            String countyCode = links.get(0).text();
//            String countyCode = links.get(0).text().substring(0, 6);
            String countyName = links.get(1).text();

            Area countyArea = Area.builder().code(countyCode)
                    .label(countyName)
                    .source(url)
                    .fullName(fullName + countyName)
                    .sortValue(sort++)
                    .level(new RemoteData<>("COUNTY"))
//                    .nodes(parseTowntr(fullName + countyName, COMMON_URL + href.subSequence(2, 5).toString() + "/" + href))
                    .build();
            StaticLog.info("		县级数据:  {}  ", countyArea);

            counties.add(countyArea);
        }
        return counties;
    }