Commit 86ef08371550748d1b6f36164acfa8e54ef6e946
1 parent
1ab15ffb
2022年6月25日16:02:31 屏蔽快手粉丝抓取接口
Showing
2 changed files
with
10 additions
and
7 deletions
src/main/java/cn/fw/freya/service/crawl/impl/KuaiShouCrawl.java
... | ... | @@ -286,7 +286,7 @@ public class KuaiShouCrawl implements CrawlStrategy { |
286 | 286 | params.put("dateType", ""); |
287 | 287 | params.put("endTime", endTime.getTime()); |
288 | 288 | params.put("page", "1"); |
289 | - params.put("startTime", startTime.getTime()); | |
289 | + params.put("startTime", startTime.getTime() - 7 * 24 * 3600 * 1000L); | |
290 | 290 | HttpConfig config = HttpConfig.custom().url("https://cp.kuaishou.com/rest/cp/creator/analysis/live/pc/detail") |
291 | 291 | .context(cookies.getContext()) |
292 | 292 | .json(JsonUtils.objectToJson(params)) |
... | ... | @@ -575,10 +575,15 @@ public class KuaiShouCrawl implements CrawlStrategy { |
575 | 575 | if (!StringUtils.hasText(res)) { |
576 | 576 | throw new BusinessException("调用快手[直播]接口失败"); |
577 | 577 | } |
578 | + Integer fansNum; | |
579 | + if (Objects.equals(response.getInteger("result"), 500002)) | |
580 | + fansNum = 0; | |
581 | + else | |
582 | + fansNum = response.getJSONObject("data").getInteger("fansCnt"); | |
578 | 583 | final Account account = accountDao.findByPhoneNoAndType(accountNo, this.getType().getValue()); |
579 | - if (Objects.nonNull(account) && Objects.nonNull(response)) { | |
580 | - accountDao.updateFans(account.getId(), response.getJSONObject("data").getInteger("fansCnt"), new Date()); | |
581 | - } else if (Objects.isNull(account) && Objects.nonNull(response)) { | |
584 | + if (Objects.nonNull(account)) | |
585 | + accountDao.updateFans(account.getId(), fansNum, new Date()); | |
586 | + else | |
582 | 587 | accountDao.save(Account.builder() |
583 | 588 | .cookiesStatus(true) |
584 | 589 | .phoneNo(accountNo) |
... | ... | @@ -587,8 +592,6 @@ public class KuaiShouCrawl implements CrawlStrategy { |
587 | 592 | .reportDate(new Date()) |
588 | 593 | .done(false) |
589 | 594 | .build()); |
590 | - } | |
591 | - assert response != null; | |
592 | 595 | return Optional.ofNullable(response.getJSONObject("data")).orElse(new JSONObject().fluentPut("fansCnt", 0)).getInteger("fansCnt"); |
593 | 596 | } |
594 | 597 | ... | ... |
src/main/java/cn/fw/freya/utils/CronCheckUtil.java
... | ... | @@ -43,7 +43,7 @@ public class CronCheckUtil { |
43 | 43 | */ |
44 | 44 | public static void main(String[] args) { |
45 | 45 | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
46 | - final List<LocalDateTime> runtimeList = CronCheckUtil.getRuntimeList("0 0/2 * * * ?", LocalDateTime.now(), 10); | |
46 | + final List<LocalDateTime> runtimeList = CronCheckUtil.getRuntimeList("0 15 0 * * ?", LocalDateTime.now(), 10); | |
47 | 47 | runtimeList.forEach(item -> System.out.println(dateTimeFormatter.format(item))); |
48 | 48 | } |
49 | 49 | } | ... | ... |