Search in sources :

Example 1 with RepItem

use of forpdateam.ru.forpda.api.reputation.models.RepItem in project ForPDA by RadiationX.

the class Reputation method getReputation.

public RepData getReputation(RepData data) throws Exception {
    if (data == null)
        return null;
    NetworkResponse response = Api.getWebClient().get("https://4pda.ru/forum/index.php?act=rep&view=history&mid=" + data.getId() + "&mode=" + data.getMode() + "&order=" + data.getSort() + "&st=" + data.getPagination().getSt());
    Matcher matcher = infoPattern.matcher(response.getBody());
    if (matcher.find()) {
        data.setId(Integer.parseInt(matcher.group(1)));
        data.setNick(ApiUtils.fromHtml(matcher.group(2)));
        if (matcher.group(3) != null) {
            data.setPositive(Integer.parseInt(matcher.group(3)));
        }
        if (matcher.group(4) != null) {
            data.setNegative(Integer.parseInt(matcher.group(4)));
        }
    }
    matcher = listPattern.matcher(response.getBody());
    String temp;
    data.getItems().clear();
    while (matcher.find()) {
        RepItem item = new RepItem();
        item.setUserId(Integer.parseInt(matcher.group(1)));
        item.setUserNick(ApiUtils.fromHtml(matcher.group(2)));
        temp = matcher.group(3);
        if (temp != null) {
            item.setSourceUrl(temp);
            item.setSourceTitle(ApiUtils.fromHtml(matcher.group(4)));
        }
        item.setTitle(ApiUtils.fromHtml(matcher.group(5)));
        item.setImage(matcher.group(6));
        item.setDate(matcher.group(7));
        data.addItem(item);
    }
    data.setPagination(Pagination.parseForum(data.getPagination(), response.getBody()));
    return data;
}
Also used : Matcher(java.util.regex.Matcher) RepItem(forpdateam.ru.forpda.api.reputation.models.RepItem) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Aggregations

NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)1 RepItem (forpdateam.ru.forpda.api.reputation.models.RepItem)1 Matcher (java.util.regex.Matcher)1