]> code.communitydata.science - taguette_google_sheet_integration.git/blob - taguette-export_tags_to_csv.py
Changed delimiter to _ from .
[taguette_google_sheet_integration.git] / taguette-export_tags_to_csv.py
1 #!/usr/bin/env python3
2
3 import re
4 import sqlite3
5 from configparser import ConfigParser
6
7 config = ConfigParser()
8 config.read('.taguette_gdocs')
9
10 ## this is project ID from the configuration
11 project_id = int(config['General']['taguette_project_id'])
12 taguette_database_file = config['General']['taguette_database_file']
13
14
15 ## connect to sqlite3
16 con = sqlite3.connect(taguette_database_file)
17 cur = con.cursor()
18
19 # Run this if you just want tags and no highlights
20 sql_stmt_get = "SELECT id, path, description FROM tags WHERE project_id = ?"
21
22 # Run this if you want tags AND highlights
23 #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 = ?"
24 cur.execute(sql_stmt_get, (project_id,))
25
26 while True:
27     row = cur.fetchone()
28     if row == None:
29         break
30         
31     tag_id, path, description = row
32
33     m = re.match(r'^(.+)\_(.*)$', path) 
34     if m:
35         axial = m.group(1)
36         tag = m.group(2)
37     else:
38         axial = ""
39         tag = path
40     
41     print("\t".join([str(tag_id), axial, tag, description]))
42

Community Data Science Collective || Want to submit a patch?