PokeAPI / pokeapi

The Pokémon API
https://pokeapi.co
BSD 3-Clause "New" or "Revised" License
4.41k stars 957 forks source link

Add LPA pokemon moves #1132

Closed programgames closed 1 month ago

programgames commented 2 months ago

Hello, I scraped pokemon moves from the Legend Pokemon Arceus version group from https://www.serebii.net/ . There is the file i generated : lpa.csv I wanted to make a fusion of this with the original file using a little script without adding all the data at the end of the file. So i tried to understand how this file is sorted and I tought that the data was sorted using colums ( in this order ) : pokemon_id, move_id, pokemon_move_method_id, level

So I created this little script :

import csv
import os

csv_file = 'lpa.csv'

out = []
print(os.getcwd())

with open(csv_file, newline='', encoding='utf-8') as file:
    reader = csv.reader(file)

    for row in reader:
        if row[0] == 'pokemon_id':
            continue
        out.append([row[0], row[1], row[2],row[3],row[4],row[5],row[6]])

csv_file2 = 'original.csv'

with open(csv_file2, newline='', encoding='utf-8') as file2:
    reader = csv.DictReader(file2)

    for ligne in reader:
        out.append([ligne['pokemon_id'], ligne['version_group_id'], ligne['move_id'],ligne['pokemon_move_method_id'],ligne['level'],ligne['order']])

sorted_data = sorted(out, key=lambda x: (int(x[0]), int(x[1]), int(x[3]),int(x[4])))

with open('reunited.csv', mode='w', newline='', encoding='utf-8') as file:
    writer = csv.writer(file)

    writer.writerow(['pokemon_id','version_group_id','move_id','pokemon_move_method_id','level','order','mastery'])
    for row in sorted_data:
        writer.writerow(row)

But as you can see in the new file generated, lpa mooves seems to be inserted in the good places, but some old mooves are mooved. Do you have an idea ? Or a better way to just insert new data ?

programgames commented 2 months ago

A good example of what happened : image

Naramsim commented 1 month ago

Hi @programgames, thanks for the PR. Could you please run black . on your branch and push again?

Naramsim commented 1 month ago

@programgames I've checked out locally your PR. I think the sorting isn't a problem. So since there are some conflicts with the master branch I'd ask you to rerun the script on the new master data and then force-push or reopen another pull request.

programgames commented 1 month ago

Ok CI is running #1149