Search in sources :

Example 1 with JUtilTextWriter

use of j.util.JUtilTextWriter in project JFramework by gugumall.

the class RegionGetter method fromBaidu.

/**
 * @throws Exception
 */
private static void fromBaidu() throws Exception {
    JHttp http = JHttp.getInstance();
    HttpClient client = http.createClient();
    String continentId = "0";
    String countryId = "1";
    String provinceId = null;
    String cityId = null;
    String countyId = null;
    JUtilTextWriter log = new JUtilTextWriter(new File("F:\\work\\JFramework_v2.0\\doc\\regions.sql"), "UTF-8");
    log.addLine("use jframework;");
    String s = JDFSFile.read(new File("F:\\work\\JFramework_v2.0\\doc\\淘宝地域\\tdist_py.js"), "GBK");
    String[] ls = JUtilString.getTokens(s, "\n");
    for (int i = 0; i < ls.length; i++) {
        if (ls[i].indexOf(":[") < 0)
            continue;
        String id = ls[i].substring(0, ls[i].indexOf(":["));
        id = JUtilString.replaceAll(id, "'", "");
        String info = ls[i].substring(ls[i].indexOf(":[") + 2, ls[i].indexOf("]"));
        info = JUtilString.replaceAll(info, "'", "");
        String[] cells = info.split(",");
        String name = cells[0];
        String pid = cells[1];
        String nameEn = cells[2];
        int idi = Integer.parseInt(id);
        // 外国城市不要
        if (idi >= 1000 && idi < 110000)
            continue;
        // 国家
        if (idi < 1000) {
            log.addLine("insert into j_country values ('" + id + "','" + pid + "','','" + name + "','" + JUtilString.toZhTw(name) + "','" + nameEn + "','',0,'T');");
            System.out.println("insert into j_country values ('" + id + "','" + pid + "','','" + name + "','" + JUtilString.toZhTw(name) + "','" + nameEn + "','',0,'T');");
        } else if (id.endsWith("0000")) {
            // 省
            if (provinceId == null || !provinceId.equals(id)) {
                provinceId = id;
            }
            String nameShort = name;
            nameShort = nameShort.replaceAll("市", "");
            nameShort = nameShort.replaceAll("维吾尔自治区", "");
            nameShort = nameShort.replaceAll("壮族自治区", "");
            nameShort = nameShort.replaceAll("回族自治区", "");
            nameShort = nameShort.replaceAll("自治区", "");
            log.addLine(" insert into j_province values ('" + id + "','" + pid + "','" + continentId + "','" + name + "','" + nameShort + "','" + JUtilString.toZhTw(name) + "','" + nameEn + "','',0,'','T');");
            System.out.println(" insert into j_province values ('" + id + "','" + pid + "','" + continentId + "','" + name + "','" + nameShort + "','" + JUtilString.toZhTw(name) + "','" + nameEn + "','',0,'','T');");
        } else if (pid.equals(provinceId)) {
            if (cityId == null || !cityId.equals(id)) {
                cityId = id;
            }
            String areaCode = "";
            String postCode = "";
            String[] data = (String[]) codes.get(id);
            if (data != null) {
                areaCode = data[0];
                postCode = data[1];
            }
            log.addLine("  insert into j_city values ('" + id + "','" + pid + "','" + countryId + "','" + continentId + "','" + name + "','" + JUtilString.toZhTw(name) + "','" + nameEn + "','" + areaCode + "',0,'" + postCode + "','T');");
            System.out.println("  insert into j_city values ('" + id + "','" + pid + "','" + countryId + "','" + continentId + "','" + name + "','" + JUtilString.toZhTw(name) + "','" + nameEn + "','" + areaCode + "',0,'" + postCode + "','T');");
        } else {
            if (countyId == null || !countyId.equals(id)) {
                countyId = id;
            }
            String areaCode = "";
            String postCode = "";
            String[] data = (String[]) codes.get(id);
            if (data != null) {
                areaCode = data[0];
                postCode = data[1];
            }
            log.addLine("   insert into j_county values ('" + id + "','" + pid + "','" + provinceId + "','" + countryId + "','" + continentId + "','" + name + "','" + JUtilString.toZhTw(name) + "','" + nameEn + "','" + areaCode + "',0,'" + postCode + "','T');");
            System.out.println("   insert into j_county values ('" + id + "','" + pid + "','" + provinceId + "','" + countryId + "','" + continentId + "','" + name + "','" + JUtilString.toZhTw(name) + "','" + nameEn + "','" + areaCode + "',0,'" + postCode + "','T');");
            JHttpContext context = new JHttpContext();
            context.addRequestHeader("Referer", "http://buy.taobao.com/auction/buy_now.jhtml");
            String zones = http.postResponse(context, client, "http://lsp.wuliu.taobao.com/locationservice/addr/output_address_town.do?l1=" + provinceId + "&l2=" + cityId + "&l3=" + countyId + "&_ksTS=1396014988093_459&callback=jsonp460", null, "UTF-8");
            zones = zones.substring(zones.indexOf("result:{") + "result:{".length());
            zones = JUtilString.replaceAll(zones, "],", "],\r\n");
            String[] zs = JUtilString.getTokens(zones, "\r\n");
            for (int j = 0; j < zs.length; j++) {
                if (zs[j].indexOf(":[") < 0)
                    continue;
                String id2 = zs[j].substring(0, zs[j].indexOf(":["));
                id2 = JUtilString.replaceAll(id2, "'", "");
                String info2 = zs[j].substring(zs[j].indexOf(":[") + 2, zs[j].indexOf("]"));
                info2 = JUtilString.replaceAll(info2, "'", "");
                String[] cells2 = info2.split(",");
                String name2 = cells2[0];
                String nameEn2 = cells2[2];
                log.addLine("    insert into j_zone values ('" + id2 + "','" + countyId + "','" + cityId + "','" + provinceId + "','" + countryId + "','" + continentId + "','" + name2 + "','" + JUtilString.toZhTw(name2) + "','" + nameEn2 + "','',0,'','T');");
                System.out.println("    insert into j_zone values ('" + id2 + "','" + countyId + "','" + cityId + "','" + provinceId + "','" + countryId + "','" + continentId + "','" + name2 + "','" + JUtilString.toZhTw(name2) + "','" + nameEn2 + "','',0,'','T');");
            }
        }
    }
    System.exit(0);
}
Also used : JUtilTextWriter(j.util.JUtilTextWriter) JHttpContext(j.http.JHttpContext) JHttp(j.http.JHttp) HttpClient(org.apache.http.client.HttpClient) JUtilString(j.util.JUtilString) JDFSFile(j.fs.JDFSFile) File(java.io.File)

Example 2 with JUtilTextWriter

use of j.util.JUtilTextWriter in project JFramework by gugumall.

the class ExcelUtilViaPOI method main.

public static void main(String[] args) throws Exception {
    JUtilTextWriter log = new JUtilTextWriter(new File("E:\\jstudio\\jframework\\doc\\regions.sql"), "UTF-8");
    log.addLine("use jframework;");
    log.addLine("delete from j_province;");
    log.addLine("delete from j_city;");
    log.addLine("delete from j_county;");
    log.addLine("delete from j_zone;");
    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("E:\\JStudio\\JFramework\\doc\\2013最新全国街道乡镇级以上行政区划代码表.xls"));
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("records");
    String provinceId = null;
    String provinceName = null;
    String cityId = null;
    String cityName = null;
    String countyId = null;
    String countyName = null;
    int lr = sheet.getLastRowNum();
    System.out.println("total:" + lr);
    for (int i = 1; i < lr; i++) {
        HSSFRow row = sheet.getRow(i);
        String code = "";
        String pcode = "";
        String name = "";
        String level = "";
        HSSFCell c0 = row.getCell(0);
        if (c0 == null)
            break;
        if (c0.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
            code = "" + (int) c0.getNumericCellValue();
        } else {
            code = c0.getStringCellValue();
        }
        HSSFCell c1 = row.getCell(1);
        if (c1.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
            pcode = "" + (int) c1.getNumericCellValue();
        } else {
            pcode = c1.getStringCellValue();
        }
        HSSFCell c2 = row.getCell(2);
        if (c2.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
            name = "" + (int) c2.getNumericCellValue();
        } else {
            name = c2.getStringCellValue();
        }
        HSSFCell c3 = row.getCell(3);
        if (c3.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
            level = "" + (int) c3.getNumericCellValue();
        } else {
            level = c3.getStringCellValue();
        }
        if (level.equals("1")) {
            provinceId = code;
            provinceName = name;
            log.addLine("insert into j_province values ('" + code + "','" + name + "','" + name + "');");
            System.out.println("insert into j_province values ('" + code + "','" + name + "','" + name + "');");
        } else if (level.equals("2")) {
            cityId = code;
            cityName = name;
            if (!name.equals("省直辖行政单位") && !name.equals("市辖区") && !name.equals("县")) {
                log.addLine(" insert into j_city values ('" + code + "','" + provinceId + "','" + name + "','','','');");
                System.out.println(" insert into j_city values ('" + code + "','" + provinceId + "','" + name + "','','','');");
            }
        } else if (level.equals("3")) {
            countyId = code;
            countyName = name;
            if (!cityName.equals("省直辖行政单位") && !cityName.equals("市辖区") && !cityName.equals("县")) {
                if (!name.equals("市辖区")) {
                    log.addLine("  insert into j_county values ('" + code + "','" + cityId + "','" + name + "','','','');");
                    System.out.println("  insert into j_county values ('" + code + "','" + cityId + "','" + name + "','','','');");
                }
            } else {
                if (!name.equals("市辖区")) {
                    log.addLine(" insert into j_city values ('" + code + "','" + provinceId + "','" + name + "','','','');");
                    System.out.println(" insert into j_city values ('" + code + "','" + provinceId + "','" + name + "','','','');");
                }
            }
        } else if (level.equals("4")) {
            if (!cityName.equals("省直辖行政单位") && !cityName.equals("市辖区") && !cityName.equals("县")) {
                log.addLine("   insert into j_zone values ('" + code + "','" + countyId + "','" + name + "','','','');");
                System.out.println("   insert into j_zone values ('" + code + "','" + countyId + "','" + name + "','','','');");
            } else {
                log.addLine("  insert into j_county values ('" + code + "','" + countyId + "','" + name + "','','','');");
                System.out.println("  insert into j_county values ('" + code + "','" + countyId + "','" + name + "','','','');");
            }
        }
    }
}
Also used : JUtilTextWriter(j.util.JUtilTextWriter) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) File(java.io.File) FileInputStream(java.io.FileInputStream) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 3 with JUtilTextWriter

use of j.util.JUtilTextWriter in project JFramework by gugumall.

the class IP method main.

/**
 * 第一步 下载"纯真IP数据库最新版"
 * 第二步 利用纯真IP数据库自带功能解压出IP文本
 * 第三步 运行以下程序生成sql文件
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    // log.log("127.3.3333.3".matches("^\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}$"));
    JUtilTextWriter log = new JUtilTextWriter(new File("E:\\jstudio\\jframework\\doc\\ips.sql"), SysConfig.sysEncoding);
    BufferedReader read = new BufferedReader(new InputStreamReader(new FileInputStream(new File("E:\\jstudio\\jframework\\doc\\ips.txt")), "gbk"));
    String line = read.readLine();
    int i = 1;
    while (line != null) {
        line = read.readLine();
        if (line.indexOf(" ") < 0 || line.indexOf("日IP数据") > 0)
            break;
        while (line.indexOf("  ") > 0) {
            line = line.replaceAll("  ", " ");
        }
        String s = line.substring(0, line.indexOf(" "));
        line = line.substring(line.indexOf(" ") + 1);
        String e = line.substring(0, line.indexOf(" "));
        line = line.substring(line.indexOf(" ") + 1);
        line = line.replaceAll("  CZ88.NET", "");
        line = line.replaceAll(" CZ88.NET", "");
        String[] ss = JUtilString.getTokens(s, ".");
        String[] ee = JUtilString.getTokens(e, ".");
        line = JUtilString.replaceAll(line, "'", "\\'");
        // System.out.println(i+", insert into j_ip values ("+i+","+calIntValue(ss)+","+calIntValue(ee)+",'"+line+"');");
        log.addLine("insert into j_ip values (" + i + "," + calIntValue(ss) + "," + calIntValue(ee) + ",'" + line + "');");
        i++;
    }
    System.out.println("end");
    log.close();
    read.close();
}
Also used : JUtilTextWriter(j.util.JUtilTextWriter) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) JUtilString(j.util.JUtilString) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 4 with JUtilTextWriter

use of j.util.JUtilTextWriter in project JFramework by gugumall.

the class Temp method main.

/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    System.out.println("start");
    String s = JDFSFile.read(new File("D:\\tomcat\\logs\\tomcat8-stderr.2014-04-29.log"));
    JUtilTextWriter w = new JUtilTextWriter(new File("f:\\temp\\test\\in.log"), "utf-8");
    for (int i = 0; i < 2000; i++) {
        w.add(s);
        w.flush();
    }
    w.close();
    System.out.println("end");
}
Also used : JUtilTextWriter(j.util.JUtilTextWriter) JDFSFile(j.fs.JDFSFile) File(java.io.File)

Aggregations

JUtilTextWriter (j.util.JUtilTextWriter)4 File (java.io.File)4 JDFSFile (j.fs.JDFSFile)2 JUtilString (j.util.JUtilString)2 FileInputStream (java.io.FileInputStream)2 JHttp (j.http.JHttp)1 JHttpContext (j.http.JHttpContext)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 HttpClient (org.apache.http.client.HttpClient)1 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)1 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)1 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)1