Created
May 22, 2020 07:51
-
-
Save Nephos/0f2dc90500ca977a4063f1a531391e51 to your computer and use it in GitHub Desktop.
Conversion d'une liste de sort (copié collé de pathfinder wiki) en csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require "json" | |
require "csv" | |
txt = File.readlines('spells.txt') | |
spells = [] | |
current_level = 0 | |
current_school = "none" | |
txt.each do |line| | |
if line.match? /^Sorts d.+ \d+$/ | |
current_level = line.split(' ')[-1].to_i | |
STDERR.puts "Add spells level #{current_level}" | |
# spells[current_level] ||= {} | |
elsif line.match? /^[^[[:space:]]]/ | |
current_school = line.chomp | |
STDERR.puts "Add spells level #{current_level} school #{current_school}" | |
# spells[current_level][current_school] ||= [] | |
elsif line.match? /^\s+$/ | |
elsif line.match? /^\s+/ | |
match = line.match /^\s+([^\.]+)\. (.+)/ | |
match = [line, line, line] if !match | |
name = match[1].strip | |
description = match[2].strip | |
realname = name.gsub(/ \([A-Z, ]+\)/im, '') | |
url = "https://www.pathfinder-fr.org/Wiki/Pathfinder-RPG.#{realname}.ashx" | |
STDERR.puts "Add spell [#{current_level}][#{current_school}] #{realname}" | |
# spells[current_level][current_school] << { name: name, description: description, url: url } | |
spells << { level: current_level, school: current_school, name: name, description: description, url: url } | |
else | |
raise "Invalid line #{line}" | |
end | |
end | |
csv_string = CSV.generate do |csv| | |
csv << ["Préparé", "Connu", "Niveau", "École", "Nom", "Description", "Url"] | |
spells.each do |spell| | |
csv << (["", ""] + spell.values) | |
end | |
end | |
# puts spells.to_json | |
puts csv_string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment