if(urlPosts == null) {
ModelException.throwException(ModelException.SCRAPPY_ERROR,"scrappyImportation " +
"method must be called before this method or it had an incorrect execution");
}
String scrappy_dump = Ejecutor.executeScrappy(urlPosts, "0");
JSONArray array = (JSONArray) JSONSerializer.toJSON(scrappy_dump);
JSONObject objeto_dump = array.getJSONObject(0);
int totalPages = 1;
if(objeto_dump.has("http://purl.org/dc/elements/1.1/TotalPages")){
JSONArray number = objeto_dump.getJSONArray("http://purl.org/dc/elements/1.1/TotalPages");
totalPages = Integer.parseInt(number.getString(0));
} else {
ModelException.sendMessage(ModelException.INFO,
"Slackers scrappy template could be out of date or incorrect. " +
"There is not http://purl.org/dc/elements/1.1/TotalPages found. Default to 1");
}
int postsCount = 0;
ModelException.sendMessage(ModelException.INFO," Maximum posts: " + Property.getPOSTS_NUMBER());
for (int j = 1; j <= totalPages; j++){
if (postsCount >= Property.getPOSTS_NUMBER()) {
break;
}
if (j > 1){
String newUrlPosts = urlPosts + ",page=" + j;
scrappy_dump = Ejecutor.executeScrappy(newUrlPosts, "0");
array = (JSONArray) JSONSerializer.toJSON(scrappy_dump);
objeto_dump = array.getJSONObject(0);
}
if (objeto_dump.has("http://purl.org/dc/elements/1.1/Posts")){
JSONArray array_objeto_post = objeto_dump.getJSONArray("http://purl.org/dc/elements/1.1/Posts");
ModelException.sendMessage(ModelException.INFO,
" Calculate reputation over "+array_objeto_post.size()+" posts");
for(int i=0;i<array_objeto_post.size();i++){
if (postsCount == Property.getPOSTS_NUMBER())
break;
JSONObject objeto_array_post = array_objeto_post.getJSONObject(i);
//System.out.println("Informacion de post:");
if(objeto_array_post.has("http://purl.org/dc/elements/1.1/PostURL")){
if(system.getUriFormat().toString().contains("/$User_Thread")) {
JSONArray array_postURL = objeto_array_post.getJSONArray(
"http://purl.org/dc/elements/1.1/PostURL");
String postURL = array_postURL.getString(0);
ModelException.sendMessage(ModelException.INFO," PostURL: " + postURL);
if(userThreads == null) {
userThreads = new ArrayList<String>();
}
userThreads.add(Ejecutor.executeScrappy(postURL, "0"));