Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
2.7 kB
3
Indexable
Never
public void getFarmableGames() {
        try {
           FarmableGame[] set = new FarmableGame[farmableGamesBody(authenticatedClient()).select("a[href]").size()];
           List<FarmableGame> farmableGames = new ArrayList<>();
            int counter = 0;
            for (Element element: farmableGamesBody(authenticatedClient()).select("div.badge_row_inner")){
                if(element.toString().contains("No card drops remaining")){
                    continue;
                }
                if(element.toString().contains("progress_info_bold") == false) continue;
                set[counter] = new FarmableGame();

                if(StringUtils.substringBetween(element.select("a[href]").toString(),"&quot;","&quot;") == null) {
                    String name = element.select("div.badge_title").toString();
                    set[counter].name = StringUtils.substringBetween(name,"\n "," &nbsp;");
                }else{
                    String name = element.select("a[href]").toString();
                    set[counter].name = StringUtils.substringBetween(name,"&quot;","&quot;");
                }
                set[counter].appId = Integer.parseInt(StringUtils.substringBetween(element.toString(),"gamebadge_","_"));


                    if(StringUtils.substringBetween(element.select("div.badge_title_stats_playtime").toString(),"; "," hrs") == null){
                        set[counter].playTime = 0;
                    }else{
                        String playTime = StringUtils.substringBetween(element.select("div.badge_title_stats_playtime").toString(),"; "," hrs");
                        set[counter].playTime = Double.parseDouble(playTime);
                    }

                set[counter].droppedCards = Integer.parseInt(StringUtils.substringBetween(
                            element.toString(),"Card drops received: ","\n"));

                    if (element.toString().contains("progress_info_bold")){
                        set[counter].remainingCards = Integer.parseInt(StringUtils.substringBetween(
                            element.toString(),"<span class=\"progress_info_bold\">"," card"));
                    }else {
                    set[counter].remainingCards = Integer.parseInt(StringUtils.substringBetween(
                            element.toString(),"You can get "," more trading cards by playing"));
                    }
                    farmableGames.add(set[counter]);
                counter++;
            }

            for (FarmableGame games: farmableGames) {
                System.out.println(games);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }