fix typo on langs.yaml and get YAML->SQL working on langs
							parent
							
								
									2e9bee76ad
								
							
						
					
					
						commit
						f253258571
					
				|  | @ -61,6 +61,66 @@ def main(): | ||||||
|         data = yaml.full_load(yl) |         data = yaml.full_load(yl) | ||||||
|     do_bulks(data, conn) |     do_bulks(data, conn) | ||||||
| 
 | 
 | ||||||
|  |     # move on to langs | ||||||
|  |     with open('langs.yaml') as yl: | ||||||
|  |         data = yaml.full_load(yl) | ||||||
|  |     do_langs(data, conn) | ||||||
|  | 
 | ||||||
|  | def do_langs(data, conn): | ||||||
|  |     table = """ | ||||||
|  | CREATE TABLE lang ( | ||||||
|  |   lang_id INTEGER PRIMARY KEY, | ||||||
|  |   name TEXT NOT NULL UNIQUE, | ||||||
|  |   speakers TEXT NOT NULL, | ||||||
|  |   rarity_id INTEGER NOT NULL, | ||||||
|  |   sourceentry_id INTEGER, | ||||||
|  |   FOREIGN KEY (rarity_id) REFERENCES langrarity(rarity_id), | ||||||
|  |   FOREIGN KEY (sourceentry_id) REFERENCES sourceentry(sourceentry_id) | ||||||
|  | ); | ||||||
|  |    """ | ||||||
|  |     c = conn.cursor() | ||||||
|  |     c.execute(table) | ||||||
|  | 
 | ||||||
|  |     # print(data) | ||||||
|  |     for i in data['language']: | ||||||
|  |         # print(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)) | ||||||
|  |         # need to insert sourceentry data first but check and make sure the | ||||||
|  |         # length is only one | ||||||
|  |         if len(srcentrydata) != 1: | ||||||
|  |             raise AssertionError('length of srcentrydata should only be 1, no more no less, on langs') | ||||||
|  |         # print("length of srcentrydata:{}\tsrcentrydata:{}".format(len(srcentrydata),srcentrydata)) | ||||||
|  |         util_insert_into_sourceentry(srcentrydata, conn) | ||||||
|  | 
 | ||||||
|  |         stmt = """ | ||||||
|  | INSERT INTO lang(name, speakers, rarity_id, sourceentry_id) | ||||||
|  | VALUES (?,?, | ||||||
|  |         (SELECT rarity_id FROM langrarity WHERE rarity_name=?), | ||||||
|  |         (SELECT sourceentry_id FROM sourceentry | ||||||
|  |         WHERE source_id=(SELECT source_id FROM source WHERE abbr=?) | ||||||
|  |         AND page_start=? | ||||||
|  |         AND page_stop=? | ||||||
|  |         ) | ||||||
|  |        ); | ||||||
|  |         """ | ||||||
|  |         print('executing on name:{}'.format(i['name'])) | ||||||
|  |         try: | ||||||
|  |             conn.execute(stmt, (i['name'], i['speakers'], i['rarity'], | ||||||
|  |                                 srcentrydata[0][0],srcentrydata[0][1],srcentrydata[0][2])) | ||||||
|  |         except Exception as e: | ||||||
|  |             print("Error creating lang: {}".format(e)) | ||||||
|  |         else: | ||||||
|  |             conn.commit() | ||||||
|  | 
 | ||||||
| def do_bulks(data, conn): | def do_bulks(data, conn): | ||||||
|     table = """ |     table = """ | ||||||
| CREATE TABLE bulk ( | CREATE TABLE bulk ( | ||||||
|  |  | ||||||
|  | @ -11,7 +11,7 @@ language: | ||||||
|         page_stop: 65 |         page_stop: 65 | ||||||
|   - name: Draconic |   - name: Draconic | ||||||
|     speakers: Dragons, reptilian humanoids |     speakers: Dragons, reptilian humanoids | ||||||
|     rarity: Commmon |     rarity: Common | ||||||
|     source: |     source: | ||||||
|       - abbr: CRB |       - abbr: CRB | ||||||
|         page_start: 65 |         page_start: 65 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue