82 lines
2.3 KiB
C#
82 lines
2.3 KiB
C#
using Newtonsoft.Json.Linq;
|
|
using Pf2eDataScrapper.Importers.Implementations.Aonprd.Compendium;
|
|
using Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder;
|
|
using Pf2eDataScrapper.Importers.Repositories;
|
|
using Pf2eDataScrapper.Processors;
|
|
|
|
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd;
|
|
|
|
/// <summary>
|
|
/// Класс обработки данных с сайта Архивов Нефеса.
|
|
/// </summary>
|
|
internal class AonprdImporter : AbstractImporter
|
|
{
|
|
/// <summary>
|
|
/// Название внешней ссылки.
|
|
/// </summary>
|
|
public const string TargetName = "Archives of Nethys Pathfinder 2e";
|
|
|
|
/// <inheritdoc/>
|
|
public override string Name => TargetName;
|
|
|
|
/// <inheritdoc/>
|
|
public override string Slug => "aonprd";
|
|
|
|
/// <inheritdoc/>
|
|
public override AbstractImporterRepository Repository { get; }
|
|
|
|
/// <summary>
|
|
/// Инструмент для работы с данными сайта Архивов Нефеса.
|
|
/// </summary>
|
|
public AonprdLoader Loader { get; }
|
|
|
|
/// <summary>
|
|
/// Конструктор класса <see cref="AonprdImporter"/>.
|
|
/// </summary>
|
|
public AonprdImporter()
|
|
{
|
|
Repository = new AonprdRepository(this, "https://elasticsearch.aonprd.com");
|
|
Loader = new(this);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override void Prepare() { }
|
|
|
|
/// <inheritdoc/>
|
|
public override void BuildSchemas() { }
|
|
|
|
/// <inheritdoc/>
|
|
public override void Import() { }
|
|
|
|
/// <inheritdoc/>
|
|
public override int CountInputs(string type)
|
|
{
|
|
return Loader.Compendium.Count(type);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override IEnumerable<ProcessorInput> ResolveInputs(string type)
|
|
{
|
|
foreach (string file in Loader.Compendium.Files(type))
|
|
{
|
|
using StreamReader fileReader = new(Path.Combine(Dir, $"{file}.json"));
|
|
JArray array = JArray.Parse(fileReader.ReadToEnd());
|
|
|
|
foreach (JToken item in array)
|
|
{
|
|
string? id = item.SelectToken("id")?.ToString();
|
|
|
|
if (id is null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (AonprdReference.ResolveType(id) == type)
|
|
{
|
|
yield return new AonprdProcessorInput(id, (JObject)item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|