| | |
| | | |
| | | @Test |
| | | public void pullDataFromYouDaoWeb() throws InterruptedException { |
| | | EnglishWordsMapper.DaoQuery daoQuery=new EnglishWordsMapper.DaoQuery(); |
| | | int page=5; |
| | | int pageSize = 100; |
| | | List<EnglishWords> list = englishWordsService.list(daoQuery,page, pageSize); |
| | | Set<String> oSpellings=new HashSet<>(); |
| | | for(EnglishWords e:list){ |
| | | oSpellings.add(e.getSpelling()); |
| | | } |
| | | Set<String> spellings=new HashSet<>(); |
| | | spellings.addAll(oSpellings); |
| | | |
| | | |
| | | |
| | | Set<String> infoSellings = YouDaoWebUtil.getBaseInfoSpellings(); |
| | | spellings.removeAll(infoSellings); |
| | | for(String s:spellings){ |
| | | try { |
| | | String result = YouDaoWebApi.getInfoBySpelling(s); |
| | | if (!StringUtil.isNullOrEmpty(result) && result.length() > 100) { |
| | | YouDaoWebUtil.saveBaseInfo(s,result); |
| | | } |
| | | }catch(Exception e){ |
| | | e.printStackTrace(); |
| | | break; |
| | | EnglishWordsMapper.DaoQuery daoQuery = new EnglishWordsMapper.DaoQuery(); |
| | | for (int page = 200; page < 300; page++) { |
| | | int pageSize = 100; |
| | | List<EnglishWords> list = englishWordsService.list(daoQuery, page, pageSize); |
| | | Set<String> oSpellings = new HashSet<>(); |
| | | for (EnglishWords e : list) { |
| | | oSpellings.add(e.getSpelling()); |
| | | } |
| | | Thread.sleep(1000 + (int) (Math.random()*1000)); |
| | | } |
| | | Set<String> spellings = new HashSet<>(); |
| | | spellings.addAll(oSpellings); |
| | | |
| | | |
| | | Set<String> ljSellings = YouDaoWebUtil.getLJSpellings(); |
| | | spellings=new HashSet<>(); |
| | | spellings.addAll(oSpellings); |
| | | spellings.removeAll(ljSellings); |
| | | for(String s:spellings){ |
| | | try { |
| | | String result = YouDaoWebApi.getLJBySpelling(s); |
| | | if (!StringUtil.isNullOrEmpty(result) && result.length() > 100) { |
| | | YouDaoWebUtil.saveLJ(s,result); |
| | | Set<String> infoSellings = YouDaoWebUtil.getBaseInfoSpellings(); |
| | | spellings.removeAll(infoSellings); |
| | | for (String s : spellings) { |
| | | try { |
| | | String result = YouDaoWebApi.getInfoBySpelling(s); |
| | | if (!StringUtil.isNullOrEmpty(result) && result.length() > 100) { |
| | | System.out.println("info:"+s); |
| | | YouDaoWebUtil.saveBaseInfo(s, result); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | break; |
| | | } |
| | | }catch(Exception e){ |
| | | e.printStackTrace(); |
| | | break; |
| | | Thread.sleep(1000 + (int) (Math.random() * 1000)); |
| | | } |
| | | |
| | | Thread.sleep(1000 + (int) (Math.random()*1000)); |
| | | |
| | | Set<String> ljSellings = YouDaoWebUtil.getLJSpellings(); |
| | | spellings = new HashSet<>(); |
| | | spellings.addAll(oSpellings); |
| | | spellings.removeAll(ljSellings); |
| | | for (String s : spellings) { |
| | | try { |
| | | String result = YouDaoWebApi.getLJBySpelling(s); |
| | | if (!StringUtil.isNullOrEmpty(result) && result.length() > 100) { |
| | | System.out.println("lj:"+s); |
| | | YouDaoWebUtil.saveLJ(s, result); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | break; |
| | | } |
| | | |
| | | Thread.sleep(1000 + (int) (Math.random() * 1000)); |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |