refactor util_srcentradata() in gendb.py
							parent
							
								
									4c67f8374e
								
							
						
					
					
						commit
						adc32dee66
					
				|  | @ -357,16 +357,7 @@ def do_gear(data, conn): | ||||||
| 
 | 
 | ||||||
|     # do the sourceentry linking |     # do the sourceentry linking | ||||||
|     for i in data['gear']: |     for i in data['gear']: | ||||||
|         srcentrydata = [] |         srcentrydata = util_srcentrydata(i) | ||||||
|         for j in i['source']: |  | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         util_insert_into_sourceentry(srcentrydata, conn) |         util_insert_into_sourceentry(srcentrydata, conn) | ||||||
|         link_sourceentry_gear(i['name'], srcentrydata, conn) |         link_sourceentry_gear(i['name'], srcentrydata, conn) | ||||||
| 
 | 
 | ||||||
|  | @ -435,19 +426,24 @@ def do_ammo(data, conn): | ||||||
|         conn.commit() |         conn.commit() | ||||||
| 
 | 
 | ||||||
|     for i in data['ammunition']: |     for i in data['ammunition']: | ||||||
|         srcentrydata = [] |         srcentrydata = util_srcentrydata(i) | ||||||
|         for j in i['source']: |  | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         util_insert_into_sourceentry(srcentrydata, conn) |         util_insert_into_sourceentry(srcentrydata, conn) | ||||||
|         link_sourceentry_ammunition(i['name'], srcentrydata, conn) |         link_sourceentry_ammunition(i['name'], srcentrydata, conn) | ||||||
| 
 | 
 | ||||||
|  | def util_srcentrydata(i): | ||||||
|  |     srcentrydata = [] | ||||||
|  |     for j in i['source']: | ||||||
|  |         abbr = j['abbr'] | ||||||
|  |         page_start = j['page_start'] | ||||||
|  |         # Not all YAML entries have page_stop data | ||||||
|  |         if 'page_stop' in j: | ||||||
|  |             page_stop = j['page_stop'] | ||||||
|  |         else: | ||||||
|  |             page_stop = page_start | ||||||
|  |         srcentrydata.append((abbr, page_start, page_stop)) | ||||||
|  |     return srcentrydata | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def link_sourceentry_ammunition(name, srcentrydata, conn): | def link_sourceentry_ammunition(name, srcentrydata, conn): | ||||||
|     stmt = """ |     stmt = """ | ||||||
|     INSERT INTO sourceentry_ammunition (sourceentry_id, ammunition_id) |     INSERT INTO sourceentry_ammunition (sourceentry_id, ammunition_id) | ||||||
|  | @ -623,32 +619,14 @@ def do_armor(data, conn): | ||||||
|         conn.commit() |         conn.commit() | ||||||
| 
 | 
 | ||||||
|     for i in data['armorgroup']: |     for i in data['armorgroup']: | ||||||
|         srcentrydata = [] |         srcentrydata = util_srcentrydata(i) | ||||||
|         for j in i['source']: |  | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         util_insert_into_sourceentry(srcentrydata, conn) |         util_insert_into_sourceentry(srcentrydata, conn) | ||||||
|         # now link the source entries to this table |         # now link the source entries to this table | ||||||
|         # TODO |         # TODO | ||||||
|         link_sourceentry_armorgroup(i['name'], srcentrydata, conn) |         link_sourceentry_armorgroup(i['name'], srcentrydata, conn) | ||||||
| 
 | 
 | ||||||
|     for i in data['armor']: |     for i in data['armor']: | ||||||
|         srcentrydata = [] |         srcentrydata = util_srcentrydata(i) | ||||||
|         for j in i['source']: |  | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         util_insert_into_sourceentry(srcentrydata, conn) |         util_insert_into_sourceentry(srcentrydata, conn) | ||||||
|         # now link the source entries to this table |         # now link the source entries to this table | ||||||
|         # TODO |         # TODO | ||||||
|  | @ -844,16 +822,7 @@ CREATE TABLE spellschool ( | ||||||
|     # print(data) |     # print(data) | ||||||
|     for i in data['spellschool']: |     for i in data['spellschool']: | ||||||
|         # print(i) |         # print(i) | ||||||
|         srcentrydata = [] |         srcentrydata = util_srcentrydata(i) | ||||||
|         for j in i['source']: |  | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         # need to insert sourceentry data first but check and make sure the |         # need to insert sourceentry data first but check and make sure the | ||||||
|         # length is only one |         # length is only one | ||||||
|         if len(srcentrydata) != 1: |         if len(srcentrydata) != 1: | ||||||
|  | @ -945,16 +914,7 @@ CREATE TABLE action ( | ||||||
|     # print(data) |     # print(data) | ||||||
|     for i in data['action']: |     for i in data['action']: | ||||||
|         # print(i) |         # print(i) | ||||||
|         srcentrydata = [] |         srcentrydata = util_srcentrydata(i) | ||||||
|         for j in i['source']: |  | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         # need to insert sourceentry data first but check and make sure the |         # need to insert sourceentry data first but check and make sure the | ||||||
|         # length is only one |         # length is only one | ||||||
|         if len(srcentrydata) != 1: |         if len(srcentrydata) != 1: | ||||||
|  | @ -1005,16 +965,7 @@ CREATE TABLE actioncategory ( | ||||||
|     # print(data) |     # print(data) | ||||||
|     for i in data['actioncategory']: |     for i in data['actioncategory']: | ||||||
|         # print(i) |         # print(i) | ||||||
|         srcentrydata = [] |         srcentrydata = util_srcentrydata(i) | ||||||
|         for j in i['source']: |  | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         # need to insert sourceentry data first but check and make sure the |         # need to insert sourceentry data first but check and make sure the | ||||||
|         # length is only one |         # length is only one | ||||||
|         if len(srcentrydata) != 1: |         if len(srcentrydata) != 1: | ||||||
|  | @ -1062,16 +1013,7 @@ CREATE TABLE lang ( | ||||||
|     # print(data) |     # print(data) | ||||||
|     for i in data['language']: |     for i in data['language']: | ||||||
|         # print(i) |         # print(i) | ||||||
|         srcentrydata = [] |         srcentrydata = util_srcentrydata(i) | ||||||
|         for j in i['source']: |  | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         # need to insert sourceentry data first but check and make sure the |         # need to insert sourceentry data first but check and make sure the | ||||||
|         # length is only one |         # length is only one | ||||||
|         if len(srcentrydata) != 1: |         if len(srcentrydata) != 1: | ||||||
|  | @ -1121,16 +1063,7 @@ CREATE TABLE bulk ( | ||||||
|     # print(data) |     # print(data) | ||||||
|     for i in data['bulk']: |     for i in data['bulk']: | ||||||
|         # print(i) |         # print(i) | ||||||
|         srcentrydata = [] |         srcentrydata = util_srcentrydata(i) | ||||||
|         for j in i['source']: |  | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         # need to insert sourceentry data first but check and make sure the |         # need to insert sourceentry data first but check and make sure the | ||||||
|         # length is only one on bulks |         # length is only one on bulks | ||||||
|         if len(srcentrydata) != 1: |         if len(srcentrydata) != 1: | ||||||
|  | @ -1188,16 +1121,7 @@ CREATE TABLE sourceentry_background ( | ||||||
| 
 | 
 | ||||||
|     # print(data) |     # print(data) | ||||||
|     for i in data['background']: |     for i in data['background']: | ||||||
|         srcentrydata = [] |         srcentrydata = util_srcentrydata(i) | ||||||
|         for j in i['source']: |  | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         stmt = "INSERT INTO background(name, descr, is_comty_use, is_specific_to_adv) VALUES (?,?,?,?)" |         stmt = "INSERT INTO background(name, descr, is_comty_use, is_specific_to_adv) VALUES (?,?,?,?)" | ||||||
|         try: |         try: | ||||||
|             conn.execute(stmt, (i['name'], i['descr'], i['is_comty_use'], |             conn.execute(stmt, (i['name'], i['descr'], i['is_comty_use'], | ||||||
|  | @ -1261,16 +1185,7 @@ CREATE TABLE sourceentry_condition ( | ||||||
|     c.execute(table) |     c.execute(table) | ||||||
| 
 | 
 | ||||||
|     for i in data['condition']: |     for i in data['condition']: | ||||||
|         srcentrydata = [] |         srcentrydata = util_srcentrydata(i) | ||||||
|         for j in i['source']: |  | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         stmt = "INSERT INTO condition(name, short_descr, descr) VALUES (?,?,?)" |         stmt = "INSERT INTO condition(name, short_descr, descr) VALUES (?,?,?)" | ||||||
|         try: |         try: | ||||||
|             conn.execute(stmt, (i['name'], i['short_descr'], i['descr'])) |             conn.execute(stmt, (i['name'], i['short_descr'], i['descr'])) | ||||||
|  | @ -1314,16 +1229,7 @@ def do_damage(data, conn): | ||||||
|     # NOW DO THE DAMAGECATEGORY stuff |     # NOW DO THE DAMAGECATEGORY stuff | ||||||
| 
 | 
 | ||||||
|     for i in data['damagecategory']: |     for i in data['damagecategory']: | ||||||
|         srcentrydata = [] |         srcentrydata = util_srcentrydata(i) | ||||||
|         for j in i['source']: |  | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         stmt = "INSERT INTO damagecategory(name, descr) VALUES (?,?)" |         stmt = "INSERT INTO damagecategory(name, descr) VALUES (?,?)" | ||||||
|         try: |         try: | ||||||
|             conn.execute(stmt, (i['name'], i['descr'])) |             conn.execute(stmt, (i['name'], i['descr'])) | ||||||
|  | @ -1340,15 +1246,7 @@ def do_damage(data, conn): | ||||||
| 
 | 
 | ||||||
|     for i in data['damagetype']: |     for i in data['damagetype']: | ||||||
|         for j in i['source']: |         for j in i['source']: | ||||||
|             srcentrydata = [] |             srcentrydata = util_srcentrydata(i) | ||||||
|             abbr = j['abbr'] |  | ||||||
|             page_start = j['page_start'] |  | ||||||
|             # Not all YAML entries have page_stop data |  | ||||||
|             if 'page_stop' in j: |  | ||||||
|                 page_stop = j['page_stop'] |  | ||||||
|             else: |  | ||||||
|                 page_stop = page_start |  | ||||||
|             srcentrydata.append((abbr, page_start, page_stop)) |  | ||||||
|         stmt = """ |         stmt = """ | ||||||
| INSERT INTO damagetype(name, abbr, damagecategory_id) | INSERT INTO damagetype(name, abbr, damagecategory_id) | ||||||
|         VALUES (?,?,( |         VALUES (?,?,( | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue