]> code.communitydata.science - taguette_google_sheet_integration.git/blob - taguette-export_tags_to_csv.py
fixed typos and errors
[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 ## connect to sqlite3
15 con = sqlite3.connect(taguette_database_file)
16 cur = con.cursor()
17
18 sql_stmt_get = "SELECT id, path, description FROM tags WHERE project_id = ?"
19 cur.execute(sql_stmt_get, (project_id,))
20
21 while True:
22     row = cur.fetchone()
23     if row == None:
24         break
25         
26     tag_id, path, description = row
27
28     m = re.match(r'^(.+)\.(.*)$', path)
29     if m:
30         axial = m.group(1)
31         tag = m.group(2)
32     else:
33         axial = ""
34         tag = path
35     
36     print("\t".join([str(tag_id), axial, tag, description]))
37

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