#!/usr/bin/env python3 import re import json import sqlite3 from configparser import ConfigParser config = ConfigParser() config.read('.taguette_gdocs') ## this is project ID from the configuration project_id = int(config['General']['taguette_project_id']) taguette_database_file = config['General']['taguette_database_file'] ## connect to sqlite3 con = sqlite3.connect(taguette_database_file) cur = con.cursor() # Run this if you just want tags and no highlights sql_stmt_get = "SELECT id, path, description FROM tags WHERE project_id = ?" # Run this if you want tags AND highlights #sql_stmt_get = "SELECT tags.id, tags.path, tags.description, highlights.snippet FROM highlight_tags INNER JOIN tags ON highlight_tags.tag_id = tags.id INNER JOIN highlights ON highlight_tags.highlight_id = highlights.id WHERE project_id = ?" cur.execute(sql_stmt_get, (project_id,)) # print out a header print("\t".join(['id', 'axial codes', 'tags', 'category', 'description'])) while True: row = cur.fetchone() if row == None: break tag_id, path, description = row tag_match = re.match(r'^(.+)\_(.*)$', path) if tag_match: axial = tag_match.group(1) tag = tag_match.group(2) else: axial = "" tag = path # look for extra category information stored in the description cat_match = re.match('^(.*)\s*(\{(.*)\})$', description) if cat_match: description = cat_match.group(1) category = json.loads(cat_match.group(2))["category"] else: category = "" print("\t".join([str(tag_id), axial, tag, category, description]))