diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-08-30 12:27:42 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-08-30 12:27:42 +1000 |
| commit | e8e58a3bb9dc233dacf573973457c5b48d369503 (patch) | |
| tree | 242500ca304c5afbb7e6506e61da4c4dfff0b175 /backend/tolData/addPickedNames.py | |
| parent | 930c12d33e1093f874a4beb4d6376621e464e8c0 (diff) | |
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
Diffstat (limited to 'backend/tolData/addPickedNames.py')
| -rwxr-xr-x | backend/tolData/addPickedNames.py | 54 |
1 files changed, 0 insertions, 54 deletions
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() |
