()
| 83 | |
| 84 | |
| 85 | def update_db(): |
| 86 | |
| 87 | print('Building gamedata DB...') |
| 88 | |
| 89 | if os.path.isfile(DB_PATH): |
| 90 | os.remove(DB_PATH) |
| 91 | |
| 92 | import eos.db |
| 93 | import eos.gamedata |
| 94 | import eos.config |
| 95 | |
| 96 | # Create the database tables |
| 97 | eos.db.gamedata_meta.create_all() |
| 98 | |
| 99 | def _readData(minerName, jsonName, keyIdName=None): |
| 100 | compiled_data = None |
| 101 | for i in itertools.count(0): |
| 102 | try: |
| 103 | with open(os.path.join(JSON_DIR, minerName, '{}.{}.json'.format(jsonName, i)), encoding='utf-8') as f: |
| 104 | rawData = json.load(f) |
| 105 | if i == 0: |
| 106 | compiled_data = {} if type(rawData) == dict else [] |
| 107 | if type(rawData) == dict: |
| 108 | compiled_data.update(rawData) |
| 109 | else: |
| 110 | compiled_data.extend(rawData) |
| 111 | except FileNotFoundError: |
| 112 | break |
| 113 | |
| 114 | if not keyIdName: |
| 115 | return compiled_data |
| 116 | # IDs in keys, rows in values |
| 117 | data = [] |
| 118 | for k, v in compiled_data.items(): |
| 119 | row = {} |
| 120 | row.update(v) |
| 121 | row[keyIdName] = int(k) |
| 122 | data.append(row) |
| 123 | return data |
| 124 | |
| 125 | def _addRows(data, cls, fieldMap=None): |
| 126 | if fieldMap is None: |
| 127 | fieldMap = {} |
| 128 | for row in data: |
| 129 | instance = cls() |
| 130 | for k, v in row.items(): |
| 131 | if isinstance(v, str): |
| 132 | v = v.strip() |
| 133 | setattr(instance, fieldMap.get(k, k), v) |
| 134 | eos.db.gamedata_session.add(instance) |
| 135 | |
| 136 | def processEveTypes(): |
| 137 | print('processing evetypes') |
| 138 | data = _readData('fsd_built', 'types', keyIdName='typeID') |
| 139 | for row in data: |
| 140 | if ( |
| 141 | # Apparently people really want Civilian modules available |
| 142 | (row['typeName_en-us'].startswith('Civilian') and "Shuttle" not in row['typeName_en-us']) |
no test coverage detected