Example #1
0
        public async Task InsertNewSeiyuu()
        {
            logger.Log("Started InsertNewSeiyuu job.");

            var lastSeiyuu = await seiyuuRepository.GetOrderedPageAsync(PredicateBuilder.True <Seiyuu>(), "MalId DESC", 0, 1);

            long lastId = lastSeiyuu.Results.First().MalId;

            string japaneseName = string.Empty;

            for (long malId = lastId + 1; malId < lastId + 100; malId++)
            {
                Person seiyuu = await SendSinglePersonRequest(malId, 0);

                if (seiyuu != null)
                {
                    logger.Log($"Parsed id:{seiyuu.MalId}: {seiyuu.Name}");
                }
                else
                {
                    logger.Log($"Omitted {malId} - not found");
                    continue;
                }

                japaneseName = string.Empty;

                if (!string.IsNullOrWhiteSpace(seiyuu.FamilyName))
                {
                    japaneseName += seiyuu.FamilyName;
                }

                if (!string.IsNullOrWhiteSpace(seiyuu.GivenName))
                {
                    japaneseName += string.IsNullOrEmpty(japaneseName) ? seiyuu.GivenName : " " + seiyuu.GivenName;
                }

                if (!IsJapanese(japaneseName))
                {
                    logger.Log($"Omitted {seiyuu.Name} - not Japanese");
                    BlacklistId(malId, "Seiyuu", "Not Japanese");
                    continue;
                }

                if (seiyuu.VoiceActingRoles.Count <= 0)
                {
                    logger.Log($"Omitted {seiyuu.Name} - not a seiyuu");
                    BlacklistId(malId, "Seiyuu", "Not a seiyuu");
                    continue;
                }

                seiyuuRepository.Add(
                    new Seiyuu
                {
                    Name         = seiyuu.Name,
                    MalId        = seiyuu.MalId,
                    ImageUrl     = EmptyStringIfPlaceholder(seiyuu.ImageURL),
                    About        = seiyuu.More,
                    Birthday     = seiyuu.Birthday.HasValue ? seiyuu.Birthday.Value.ToString("dd-MM-yyyy") : string.Empty,
                    Popularity   = seiyuu.MemberFavorites,
                    JapaneseName = japaneseName
                }
                    );

                await seiyuuRepository.CommitAsync();

                logger.Log($"Inserted {seiyuu.Name} with MalId: {seiyuu.MalId}");

                foreach (VoiceActingRole role in seiyuu.VoiceActingRoles)
                {
                    await InsertRole(seiyuu.MalId, role, new List <Role>());
                }
            }

            logger.Log("Finished InsertNewSeiyuu job.");
        }