added new configuration file and README
updated code to read from the config
This commit is contained in:
parent
5dbb55e4d1
commit
c085be83a7
7
.taguette_gdocs
Normal file
7
.taguette_gdocs
Normal file
@ -0,0 +1,7 @@
|
||||
[General]
|
||||
|
||||
taguette_database_file = ./taguette-working.sqlite3
|
||||
taguette_project_id = CHANGEME
|
||||
|
||||
gsheet_id = CHANGEME
|
||||
gsheet_gid = CHANGME
|
||||
71
README.md
Normal file
71
README.md
Normal file
@ -0,0 +1,71 @@
|
||||
## Step 0: Setup
|
||||
|
||||
If you have not already done so, please edit the file `.taguette_gdocs` in this
|
||||
directory. You must enter ever variable marked with "CHANGME." You only need to
|
||||
do this once.
|
||||
|
||||
In order to not commit your changes into git, you can run this command:
|
||||
|
||||
```
|
||||
git update-index --assume-unchanged .taguette_gdocs
|
||||
```
|
||||
|
||||
I also create a directory called `taguette_backups` like:
|
||||
|
||||
```
|
||||
mkdir db_backups
|
||||
```
|
||||
|
||||
## Step 1: Backing things up
|
||||
|
||||
Do this every time before you run the script:
|
||||
|
||||
```
|
||||
sudo systemctl stop taguette
|
||||
BACKUP_FILE="taguette-snapshot-$(date +%Y%m%d-%H%M%S).sqlite3"
|
||||
sudo cp /var/lib/taguette/taguette.sqlite3 "taguette_backups/$BACKUP_FILE"
|
||||
cp "taguette_backups/$BACKUP_FILE" ./taguette-working.sqlite3
|
||||
```
|
||||
|
||||
The first line shuts down Taguette. The second line just creates the backup
|
||||
file name. The third and fourt lines will create a new backup file and copy the
|
||||
backup file into the `./taguette-working.sqlite3`.
|
||||
|
||||
### Step 2a: Import from Google Sheets into the database
|
||||
|
||||
If everything is setup well, you should just need to run:
|
||||
|
||||
```
|
||||
python3 taguette-update_tags_from_sheet.py
|
||||
```
|
||||
|
||||
Check for errors! If you don't see any, you will need to copy the database back
|
||||
like:
|
||||
|
||||
```
|
||||
sudo cp ./taguette-working.sqlite3 /var/lib/taguette/taguette.sqlite3
|
||||
```
|
||||
|
||||
### Step 2b: Exporting from the database
|
||||
|
||||
Exporting tags should be as easy as:
|
||||
|
||||
```
|
||||
python3 taguette-export_tags_to_csv.py > exported_tags.tsv
|
||||
```
|
||||
|
||||
This will create a new file called `exported_tags.tsv` which you can manually
|
||||
move into the spreadsheet.
|
||||
|
||||
## Step 3: Restarting Taguette
|
||||
|
||||
Once everything looks good, go ahead and restart Taguette like:
|
||||
|
||||
```
|
||||
sudo systemctl start taguette
|
||||
```
|
||||
|
||||
You can check it with `systemctl status taguette` but keep in mind it takes
|
||||
some time startup.
|
||||
|
||||
|
||||
@ -2,14 +2,19 @@
|
||||
|
||||
import re
|
||||
import sqlite3
|
||||
from configparser 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-working.sqlite3')
|
||||
con = sqlite3.connect(taguette_database_file)
|
||||
cur = con.cursor()
|
||||
|
||||
## this is the hardcoded project id
|
||||
project_id = 13
|
||||
|
||||
sql_stmt_get = "SELECT id, path, description FROM tags WHERE project_id = ?"
|
||||
cur.execute(sql_stmt_get, (project_id,))
|
||||
|
||||
|
||||
@ -3,13 +3,18 @@
|
||||
import requests
|
||||
from csv import DictReader
|
||||
import sqlite3
|
||||
from configparser ConfigParser
|
||||
|
||||
gsheet_id = "1bfKljA7vw2V4yKrowxCPLdYaBrTzty5_O7msbuFw7Nc"
|
||||
gsheet_gid = "0"
|
||||
config = ConfigParser()
|
||||
config.read('.taguette_gdocs')
|
||||
|
||||
## this is the hardcoded project id
|
||||
project_id = 13
|
||||
## this is project ID from the configuration
|
||||
project_id = int(config['General']['taguette_project_id'])
|
||||
taguette_database_file = config['General']['taguette_database_file']
|
||||
|
||||
## load the googgle sheet ID from the configuration
|
||||
gsheet_id = config['General']['gsheet_id']
|
||||
gsheet_gid = config['General']['gsheet_gid']
|
||||
|
||||
## get the spreadsheet data
|
||||
axial_url = f"https://docs.google.com/spreadsheets/d/{gsheet_id}/export?format=csv&id={gsheet_id}&gid={gsheet_gid}"
|
||||
@ -17,7 +22,7 @@ rv = requests.get(axial_url)
|
||||
csv_text = rv.content.decode('utf-8')
|
||||
|
||||
## connect to sqlite3
|
||||
con = sqlite3.connect('taguette-working.sqlite3')
|
||||
con = sqlite3.connect(taguette_database_file)
|
||||
cur = con.cursor()
|
||||
|
||||
## import taguette.database as tagdb
|
||||
|
||||
Loading…
Reference in New Issue
Block a user