/** * @param OutputInterface $output */ private function findCommunities(OutputInterface $output) { $this->logger->addInfo('Finding new communities'); $communities = array(); try { for ($page = 1; $page <= 20; $page++) { $responseMessage = $this->parseService->getPage($this->makeCommunitiesMoreUrl(), true, $this->makeCommunitiesUrl(), array('t:zone' => 'bunchZone', 'bunchIndex' => $page)); $response = json_decode($responseMessage); if (!$response) { $this->logger->addInfo(sprintf('Empty page %s', $page)); break; } $pageCommunities = $this->parseService->getCommunities($response->content); $this->logger->addInfo(sprintf('Page %s parsed successful, get %s communities', $page, count($pageCommunities))); $communities = $communities + $pageCommunities; usleep(rand(500, 1500) * 1000); } } catch (RuntimeException $e) { $this->logger->addInfo('Exception: ' . $e->getMessage() . ' ' . $e->getCode()); } foreach ($communities as $parsedCommunity) { $community = $this->pantheonRepository->find($parsedCommunity->id); if ($community) { continue; } $community = new Pantheon(); $community->setId($parsedCommunity->id)->setImg($parsedCommunity->pic)->setName($parsedCommunity->name)->setIsActive(0)->setUpdatedAt(new DateTime()); $this->em->persist($community); } $this->em->flush(); }
/** * @param string $playerId * @param OutputInterface $output */ private function getPlayerItems($playerId, OutputInterface $output) { $data = $this->parseService->getPlayerItems($playerId); if (empty($data->resp)) { $output->writeln(sprintf('<comment>Empty dress response for %s</comment>', $playerId)); return; } $slots = $data->resp->slot2item; if (isset($slots->MAINHAND)) { if ($slots->MAINHAND->name == 'Оберег') { $slots->MAINHAND->name = 'Метла'; } $this->addItem($slots->MAINHAND, $playerId, $output); } if (isset($slots->OFFHAND)) { $this->addItem($slots->OFFHAND, $playerId, $output); } if (isset($slots->RING_LUCK)) { $this->addItem($slots->RING_LUCK, $playerId, $output); } if (isset($slots->RING_PRECISION)) { $this->addItem($slots->RING_PRECISION, $playerId, $output); } if (isset($slots->RING_VALOR)) { $this->addItem($slots->RING_VALOR, $playerId, $output); } if (isset($slots->RING_ZEAL)) { $this->addItem($slots->RING_ZEAL, $playerId, $output); } if (isset($slots->RUNE_1)) { $this->addItem($slots->RUNE_1, $playerId, $output); } if (isset($slots->RUNE_2)) { $this->addItem($slots->RUNE_2, $playerId, $output); } if (isset($slots->RUNE_3)) { $this->addItem($slots->RUNE_3, $playerId, $output); } if (isset($slots->RUNE_4)) { $this->addItem($slots->RUNE_4, $playerId, $output); } /* if ($slots->TROPHY_1) { $this->addItem($slots->MAINHAND, $playerId, $output); } if ($slots->TROPHY_2) { $this->addItem($slots->MAINHAND, $playerId, $output); }*/ $this->em->flush(); $output->writeln(sprintf('<info>Successfully parsed player %s</info>', $playerId)); }
/** * @param CommunityInterface $community * @param OutputInterface $output * @param string $type */ private function updateCommunityMembers(CommunityInterface $community, OutputInterface $output, $type) { $this->logger->addInfo(sprintf('Checking %s "%s" with %s', $type, $community->getName(), $community->getId())); $members = array(); try { for ($page = 1; $page <= 20; $page++) { if ($this->regionService->getRegion() == RegionService::RU_REGION) { $responseMessage = $this->parseService->getPage($this->makeCommunityMembersMoreUrl($community->getId()), true, $this->makeCommunityMembersUrl($community->getId()), array('t:zone' => 'bunchZone', 'bunchIndex' => $page)); $response = json_decode($responseMessage); } else { $response = $this->parseService->getPage($this->makeCommunityMembersUrl($community->getId()) . '?page=' . $page, false, $this->makeCommunityMembersUrl($community->getId())); } if (!$response) { $this->logger->addInfo(sprintf('Empty page %s', $page)); break; } if ($this->regionService->getRegion() == RegionService::RU_REGION) { $pageMembers = $this->parseService->getMembersFromCommunityPage($response->content); } else { $pageMembers = $this->parseService->getMembersFromCommunityPage($response); } $this->logger->addInfo(sprintf('Page %s parsed successful, get %s members', $page, count($pageMembers))); $members = $members + $pageMembers; usleep(rand(500, 1500) * 1000); } } catch (RuntimeException $e) { $this->logger->addInfo('Exception: ' . $e->getMessage() . ' ' . $e->getCode()); } if ($type == $this::TYPE_PANTHEON) { $dbMembers = $this->playerRepository->findBy(array('pantheon' => $community->getId())); } elseif ($type == $this::TYPE_COMMUNITY) { $dbMembers = $this->playerRepository->findByCommunity($community); } else { throw new \InvalidArgumentException(sprintf('Unknown community type "%s" to find members', $type)); } /** @var Player $member */ foreach ($dbMembers as $member) { if ($type == $this::TYPE_PANTHEON) { $member->removePantheon(); } elseif ($type == $this::TYPE_COMMUNITY) { $member->getCommunities()->removeElement($community); } else { throw new \InvalidArgumentException(sprintf('Unknown community type "%s" to remove community', $type)); } } foreach ($members as $parsedMember) { $player = $this->playerRepository->find($parsedMember->id); if (!$player) { $player = new Player(); $player->setId($parsedMember->id); $this->em->persist($player); } if ($parsedMember->name) { $player->setName($parsedMember->name); } if ($parsedMember->nick) { $player->setNick($parsedMember->nick); } else { $player->setNick(''); } $community->addMember($player); if ($type == $this::TYPE_PANTHEON) { $player->setPantheon($community); } elseif ($type == $this::TYPE_COMMUNITY) { $player->getCommunities()->add($community); } else { throw new \InvalidArgumentException(sprintf('Unknown community type "%s" to add for member', $type)); } } $community->setUpdatedAt(new DateTime()); usleep(rand(500, 1500) * 1000); }