In [1]:
from csv import DictReader
from pprint import pprint
from decimal import Decimal
with open('party.multisheet/stats-Table 1.csv') as infile:
    stats = list(DictReader(infile))
with open('party.multisheet/equipment-Table 1.csv') as infile:
    equipment = list(DictReader(infile))
with open('party.multisheet/weapons-Table 1.csv') as infile:
    weapons = list(DictReader(infile))
pprint(stats)


[{'charisma': '14',
  'class': 'Fighter',
  'constitution': '15',
  'dexterity': '15',
  'intelligence': '11',
  'level': '5',
  'name': 'Aelfryth',
  'role': 'Thane',
  'strength': '16',
  'wisdom': '14'},
 {'charisma': '12',
  'class': 'Fighter',
  'constitution': '16',
  'dexterity': '11',
  'intelligence': '9',
  'level': '4',
  'name': 'Godric',
  'role': 'Warband Member',
  'strength': '17',
  'wisdom': '7'},
 {'charisma': '11',
  'class': 'Sourceror',
  'constitution': '12',
  'dexterity': '14',
  'intelligence': '17',
  'level': '5',
  'name': 'Leofflaed',
  'role': 'Enigma',
  'strength': '8',
  'wisdom': '11'},
 {'charisma': '10',
  'class': 'Thief',
  'constitution': '14',
  'dexterity': '15',
  'intelligence': '12',
  'level': '3',
  'name': 'Wigstan',
  'role': 'Runaway Thrall',
  'strength': '14',
  'wisdom': '9'}]

In [7]:
equip_fields = 'quantity cost notes owner'.split()
equip_fields.append('weight each')
party = {}
for character in stats:
    party[character['name']] = {
        'class': character['class'],
        'role': character['role'],
        'level': int(character['level']),
        'stats': {f: int(character[f]) for f in 
                  'strength intelligence wisdom dexterity constitution charisma'
                  .split()},
        'equipment': {}
        }
    for itm in equipment:
        if itm['owner'] == character['name']:
            equip = {'magic': itm['magic'], 
                     'materials': itm['materials'].split(', '),
                     'quantity': int(itm['quantity']),
                     'weight each': float(itm['weight each']),
                     'cost': float(itm['weight each']),
                     'notes': itm['notes'],
                    }
            for weapon in weapons:
                if weapon['name'] == itm['name']:
                    equip['damage'] = weapon['damage']
            party[character['name']]['equipment'][itm['name']] = equip

In [8]:
party


Out[8]:
{'Aelfryth': {'class': 'Fighter',
  'equipment': {'Tent': {'cost': 15.0,
    'magic': '',
    'materials': ['cloth'],
    'notes': 'sleeps 4',
    'quantity': 1,
    'weight each': 15.0},
   'arrows': {'cost': 0.1,
    'magic': '',
    'materials': ['wood', 'iron'],
    'notes': '',
    'quantity': 12,
    'weight each': 0.1},
   'bow': {'cost': 2.0,
    'damage': 'd6',
    'magic': '',
    'materials': ['wood'],
    'notes': '',
    'quantity': 1,
    'weight each': 2.0},
   'shield': {'cost': 10.0,
    'magic': '',
    'materials': ['wood', 'cloth'],
    'notes': '',
    'quantity': 1,
    'weight each': 10.0}},
  'level': 5,
  'role': 'Thane',
  'stats': {'charisma': 14,
   'constitution': 15,
   'dexterity': 15,
   'intelligence': 11,
   'strength': 16,
   'wisdom': 14}},
 'Godric': {'class': 'Fighter',
  'equipment': {'30’ rope': {'cost': 10.0,
    'magic': '',
    'materials': ['hemp'],
    'notes': '',
    'quantity': 1,
    'weight each': 10.0},
   'battleaxe': {'cost': 7.0,
    'damage': 'd8',
    'magic': '+1',
    'materials': ['wood', 'iron'],
    'notes': '',
    'quantity': 1,
    'weight each': 7.0},
   'torches': {'cost': 2.0,
    'magic': '',
    'materials': ['wood'],
    'notes': '',
    'quantity': 6,
    'weight each': 2.0}},
  'level': 4,
  'role': 'Warband Member',
  'stats': {'charisma': 12,
   'constitution': 16,
   'dexterity': 11,
   'intelligence': 9,
   'strength': 17,
   'wisdom': 7}},
 'Leofflaed': {'class': 'Sourceror',
  'equipment': {'Oil of Revelation': {'cost': 1.0,
    'magic': 'Y',
    'materials': ['oil', 'spices'],
    'notes': 'Burned in any lamp, its light reveals all illusions, disguises, invisible',
    'quantity': 1,
    'weight each': 1.0},
   'Unfailing Flint': {'cost': 0.1,
    'magic': 'Y',
    'materials': ['stone'],
    'notes': 'Immediately ignites in any weather',
    'quantity': 1,
    'weight each': 0.1},
   'lamp': {'cost': 0.2,
    'magic': '',
    'materials': ['clay'],
    'notes': '',
    'quantity': 1,
    'weight each': 0.2}},
  'level': 5,
  'role': 'Enigma',
  'stats': {'charisma': 11,
   'constitution': 12,
   'dexterity': 14,
   'intelligence': 17,
   'strength': 8,
   'wisdom': 11}},
 'Wigstan': {'class': 'Thief',
  'equipment': {'cookpot': {'cost': 10.0,
    'magic': '',
    'materials': ['iron'],
    'notes': '',
    'quantity': 1,
    'weight each': 10.0},
   'cudgel': {'cost': 3.0,
    'damage': 'd6',
    'magic': '',
    'materials': ['wood'],
    'notes': '',
    'quantity': 1,
    'weight each': 3.0},
   'dagger': {'cost': 1.0,
    'damage': 'd4',
    'magic': '',
    'materials': ['iron'],
    'notes': '',
    'quantity': 1,
    'weight each': 1.0},
   'torches': {'cost': 2.0,
    'magic': '',
    'materials': ['wood'],
    'notes': '',
    'quantity': 3,
    'weight each': 2.0}},
  'level': 3,
  'role': 'Runaway Thrall',
  'stats': {'charisma': 10,
   'constitution': 14,
   'dexterity': 15,
   'intelligence': 12,
   'strength': 14,
   'wisdom': 9}}}

In [9]:
type(party['Aelfryth']['equipment']['arrows']['cost'])


Out[9]:
float

In [10]:
import json

In [14]:
p2 = [{'name': k, **v} for (k, v) in party.items()]

In [16]:
with open('party.json', 'w') as outfile:
    json.dump(p2, outfile, indent=2)

In [11]:
for (name, doc) in party.items():
    with open('party/%s.json' % name, 'w') as outfile:
        doc['name'] = name
        json.dump(doc, outfile, indent=2)

In [12]:
!cat party/Aelfryth.json


{
  "class": "Fighter",
  "role": "Thane",
  "level": 5,
  "equipment": {
    "bow": {
      "quantity": 1,
      "materials": [
        "wood"
      ],
      "weight each": 2.0,
      "magic": "",
      "notes": "",
      "cost": 2.0,
      "damage": "d6"
    },
    "Tent": {
      "quantity": 1,
      "materials": [
        "cloth"
      ],
      "weight each": 15.0,
      "magic": "",
      "notes": "sleeps 4",
      "cost": 15.0
    },
    "shield": {
      "quantity": 1,
      "materials": [
        "wood",
        "cloth"
      ],
      "weight each": 10.0,
      "magic": "",
      "notes": "",
      "cost": 10.0
    },
    "arrows": {
      "quantity": 12,
      "materials": [
        "wood",
        "iron"
      ],
      "weight each": 0.1,
      "magic": "",
      "notes": "",
      "cost": 0.1
    }
  },
  "name": "Aelfryth",
  "stats": {
    "dexterity": 15,
    "charisma": 14,
    "strength": 16,
    "wisdom": 14,
    "intelligence": 11,
    "constitution": 15
  }
}

In [ ]: