from csv import DictReader
import sqlite3
from configparser import ConfigParser
+import re
+import json
config = ConfigParser()
config.read('.taguette_gdocs')
for row in DictReader(csv_text.splitlines(), delimiter=","):
#print(row)
- tag_id = row['ID']
+ tag_id = row['id']
new_name = row['tag']
- axial_code = row['Axial Codes']
+ axial_code = row['axial codes']
+ category = row['category']
+ description = row['description']
sql_stmt_get = "SELECT id, path, description from TAGS where id = ? AND project_id = ?"
cur.execute(sql_stmt_get, (tag_id, project_id))
oldname = tag_info[0][1]
old_description = tag_info[0][2]
- if row['Axial Codes']:
- newname = row['Axial Codes'].lower() + "_" + new_name.lower()
+ if axial_code:
+ newname = axial_code.lower() + "_" + new_name.lower()
else:
newname = new_name.lower()
+ new_description = description
+ if description and category:
+ new_description += " "
+ if category:
+ new_description += json.dumps({'category' : category})
+
if not oldname == newname:
- #print(tag_id)
sql_stmt_update = "UPDATE tags SET path = ? WHERE project_id = ? AND id = ?"
cur.execute(sql_stmt_update, (newname, project_id, tag_id))
print(f"UPDATE TAG: {oldname} → {newname}")
- if row["description"].strip() != old_description.strip():
+ if new_description.strip() != old_description.strip():
sql_stmt_update = "UPDATE tags SET description = ? WHERE project_id = ? AND id = ?"
- cur.execute(sql_stmt_update, (row['description'], project_id, tag_id))
- print(f"UPDATE DESC: {old_description} → {row['description']}")
+ cur.execute(sql_stmt_update, (new_description, project_id, tag_id))
+ print(f"UPDATE DESC: {old_description} → {new_description}")
con.commit()
con.close()