From e8e58a3bb9dc233dacf573973457c5b48d369503 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Tue, 30 Aug 2022 12:27:42 +1000 Subject: Add scripts for generating eol/enwiki mappings - New data sources: OTOL taxonomy, EOL provider-ids, Wikidata dump - Add 'node_iucn' table - Remove 'redirected' field from 'wiki_ids' table - Make 'eol_ids' table have 'name' as the primary key - Combine name-generation scripts into genNameData.py - Combine description-generation scripts into genDescData.py --- backend/tolData/addPickedNames.py | 54 --------------------------------------- 1 file changed, 54 deletions(-) delete mode 100755 backend/tolData/addPickedNames.py (limited to 'backend/tolData/addPickedNames.py') diff --git a/backend/tolData/addPickedNames.py b/backend/tolData/addPickedNames.py deleted file mode 100755 index 9b56422..0000000 --- a/backend/tolData/addPickedNames.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/python3 - -import sys -import sqlite3 - -import argparse -parser = argparse.ArgumentParser(description=""" -Reads alt-name data from a file, and adds it to the database's 'names' table -""", formatter_class=argparse.RawDescriptionHelpFormatter) -parser.parse_args() - -dbFile = "data.db" -pickedNamesFile = "pickedNames.txt" - -print("Opening database") -dbCon = sqlite3.connect(dbFile) -dbCur = dbCon.cursor() - -print("Iterating through picked-names file") -with open(pickedNamesFile) as file: - for line in file: - # Get record data - nodeName, altName, prefAlt = line.lower().rstrip().split("|") - prefAlt = int(prefAlt) - # Check whether there exists a node with the name - row = dbCur.execute("SELECT name from nodes where name = ?", (nodeName,)).fetchone() - if row == None: - print(f"ERROR: No node with name \"{nodeName}\" exists") - break - # Remove any existing preferred-alt status - if prefAlt == 1: - query = "SELECT name, alt_name FROM names WHERE name = ? AND pref_alt = 1" - row = dbCur.execute(query, (nodeName,)).fetchone() - if row != None and row[1] != altName: - print(f"Removing pref-alt status from alt-name {row[1]} for {nodeName}") - dbCur.execute("UPDATE names SET pref_alt = 0 WHERE name = ? AND alt_name = ?", row) - # Check for an existing record - if nodeName == altName: - continue - query = "SELECT name, alt_name, pref_alt FROM names WHERE name = ? AND alt_name = ?" - row = dbCur.execute(query, (nodeName, altName)).fetchone() - if row == None: - print(f"Adding record for alt-name {altName} for {nodeName}") - dbCur.execute("INSERT INTO names VALUES (?, ?, ?, 'picked')", (nodeName, altName, prefAlt)) - else: - # Update existing record - if row[2] != prefAlt: - print(f"Updating record for alt-name {altName} for {nodeName}") - dbCur.execute("UPDATE names SET pref_alt = ?, src = 'picked' WHERE name = ? AND alt_name = ?", - (prefAlt, nodeName, altName)) - -print("Closing database") -dbCon.commit() -dbCon.close() -- cgit v1.2.3