4 from csv import DictReader
6 from configparser import ConfigParser
8 config = ConfigParser()
9 config.read('.taguette_gdocs')
11 ## this is project ID from the configuration
12 project_id = int(config['General']['taguette_project_id'])
13 taguette_database_file = config['General']['taguette_database_file']
15 ## load the googgle sheet ID from the configuration
16 gsheet_id = config['General']['gsheet_id']
17 gsheet_gid = config['General']['gsheet_gid']
19 ## get the spreadsheet data
20 axial_url = f"https://docs.google.com/spreadsheets/d/{gsheet_id}/export?format=csv&id={gsheet_id}&gid={gsheet_gid}"
21 rv = requests.get(axial_url)
22 csv_text = rv.content.decode('utf-8')
25 con = sqlite3.connect(taguette_database_file)
28 ## import taguette.database as tagdb
29 ## db = tagdb.connect("sqlite:////home/mako/taguette-snapshot-20210422-1.sqlite3")
31 for row in DictReader(csv_text.splitlines(), delimiter=","):
35 axial_code = row['Axial Codes']
37 sql_stmt_get = "SELECT id, path, description from TAGS where id = ? AND project_id = ?"
38 cur.execute(sql_stmt_get, (tag_id, project_id))
39 tag_info = cur.fetchall()
42 print(f"ERROR: '{id}' is not unique, SKIPPING")
43 elif len(tag_info) == 0:
44 print(f"ERROR: 'tag with ID {id}' does not exist, SKIPPING")
46 oldname = tag_info[0][1]
47 old_description = tag_info[0][2]
49 if row['Axial Codes']:
50 newname = row['Axial Codes'].lower() + "_" + new_name.lower()
52 newname = new_name.lower()
54 if not oldname == newname:
56 sql_stmt_update = "UPDATE tags SET path = ? WHERE project_id = ? AND id = ?"
57 cur.execute(sql_stmt_update, (newname, project_id, tag_id))
58 print(f"UPDATE TAG: {oldname} → {newname}")
60 if row["description"].strip() != old_description.strip():
61 sql_stmt_update = "UPDATE tags SET description = ? WHERE project_id = ? AND id = ?"
62 cur.execute(sql_stmt_update, (row['description'], project_id, tag_id))
63 print(f"UPDATE DESC: {old_description} → {row['description']}")