4 from csv import DictReader
7 gsheet_id = "1bfKljA7vw2V4yKrowxCPLdYaBrTzty5_O7msbuFw7Nc"
10 ## this is the hardcoded project id
14 ## get the spreadsheet data
15 axial_url = f"https://docs.google.com/spreadsheets/d/{gsheet_id}/export?format=csv&id={gsheet_id}&gid={gsheet_gid}"
16 rv = requests.get(axial_url)
17 csv_text = rv.content.decode('utf-8')
20 con = sqlite3.connect('taguette-working.sqlite3')
23 ## import taguette.database as tagdb
24 ## db = tagdb.connect("sqlite:////home/mako/taguette-snapshot-20210422-1.sqlite3")
26 for row in DictReader(csv_text.splitlines(), delimiter=","):
30 axial_code = row['Axial Codes']
32 sql_stmt_get = "SELECT id, path, description from TAGS where id = ? AND project_id = ?"
33 cur.execute(sql_stmt_get, (tag_id, project_id))
34 tag_info = cur.fetchall()
37 print(f"ERROR: '{id}' is not unique, SKIPPING")
38 elif len(tag_info) == 0:
39 print(f"ERROR: 'tag with ID {id}' does not exist, SKIPPING")
41 oldname = tag_info[0][1]
42 old_description = tag_info[0][2]
44 if row['Axial Codes']:
45 newname = row['Axial Codes'].lower() + "." + new_name.lower()
47 newname = new_name.lower()
49 if not oldname == newname:
51 sql_stmt_update = "UPDATE tags SET path = ? WHERE project_id = ? AND id = ?"
52 cur.execute(sql_stmt_update, (newname, project_id, tag_id))
53 print(f"UPDATE TAG: {oldname} → {newname}")
55 if row["description"].strip() != old_description.strip():
56 sql_stmt_update = "UPDATE tags SET description = ? WHERE project_id = ? AND id = ?"
57 cur.execute(sql_stmt_update, (row['description'], project_id, tag_id))
58 print(f"UPDATE DESC: {old_description} → {row['description']}")