Skip to content

Instantly share code, notes, and snippets.

@Serentty
Created November 25, 2020 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Serentty/4424b20a8184b5084db346cc534c5d4e to your computer and use it in GitHub Desktop.
Save Serentty/4424b20a8184b5084db346cc534c5d4e to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using PokeApiNet;
namespace GetPokémonData
{
class Program
{
static async Task<(PokemonSpecies, PokemonSpecies)> GetEvolutionPair(PokeApiClient client, EvolutionChain chain)
{
var first = await client.GetResourceAsync<PokemonSpecies>(chain.Chain.Species.Name);
var next = chain.Chain;
while(next.EvolvesTo.Count != 0)
next = next.EvolvesTo[0];
var last = await client.GetResourceAsync<PokemonSpecies>(next.Species.Name);
return (first, last);
}
static string GetJapaneseName(PokemonSpecies species)
{
foreach(var name in species.Names)
{
if(name.Language.Name.StartsWith("ja"))
return name.Name;
}
throw new ArgumentException(); // Didn't find anything, so let's crash!
// We probably got enough Pokémon by now anyway.
}
static async Task Main(string[] args)
{
PokeApiClient client = new();
List<EvolutionChain> chains = new();
for(int i = 1; i <= 10000; i++)
{
try { chains.Add(await client.GetResourceAsync<EvolutionChain>(i)); }
catch { break; } // We failed getting one, so let's just stop here.
Console.WriteLine($"Got chain {i}.");
}
foreach(var chain in chains)
{
var (baby, evolved) = await GetEvolutionPair(client, chain);
try { Console.WriteLine($"{GetJapaneseName(baby)},{GetJapaneseName(evolved)}"); }
catch { break; } // No Japanese name? We're probably at the end of usable data then.
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment