diff options
| author | 2021-07-23 23:32:25 -0400 | |
|---|---|---|
| committer | 2021-07-26 22:55:26 -0400 | |
| commit | fb966b02d4c2817ae0f1445dfc4725624cfce1b8 (patch) | |
| tree | 7296900e8a1e5c527806545d5a4fa1347fc3aec4 | |
| parent | use an actual schema for storing tag data (diff) | |
add 'list tags' and 'list cards'
| -rwxr-xr-x | underwriter | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/underwriter b/underwriter index dcc2012..3dd7295 100755 --- a/underwriter +++ b/underwriter @@ -93,6 +93,48 @@ END; cur.remove_card(name) self.db.commit() + def list_cards(self): + return \ + self.db.execute("SELECT name FROM cards").fetchall() + def list_tags(self): + return \ + self.db.execute("SELECT name FROM tags").fetchall() + + def tags_for_cards(self, cards): + return self.db.executemany(""" +SELECT tags.name FROM tagmap +INNER JOIN tags on tagmap.tag = tags.id WHERE tagmap.card = +(SELECT id FROM cards WHERE name = ? LIMIT 1); + """, cards).fetchall() + + def tags_for_cards(self, cards): + for c in cards: + print(c) + for (t,) in self.db.execute(""" + SELECT tags.name FROM tagmap + INNER JOIN tags + ON tagmap.tag = tags.id + WHERE tagmap.card = (SELECT + id FROM cards WHERE name = ? + LIMIT 1); + """, (c,)).fetchall(): + print(t) + print("===================") + + def cards_for_tags(self, tags): + for t in tags: + print(t) + for (c,) in self.db.execute(""" + SELECT cards.name FROM tagmap + INNER JOIN cards + ON tagmap.card = cards.id + WHERE tagmap.tag = (SELECT + id FROM tags WHERE name = ? + LIMIT 1); + """, (t,)).fetchall(): + print(c) + print("===================") + def __init__(self, name): if not os.path.isfile(name): self.db = Context.initdb(name) @@ -107,6 +149,9 @@ tag file [tags...]: add a file to the database if it not already in it, and add 0 or more tags to it remove files...: remove a file from the database untag file [tags...]: remove tags from a file + +list tags cards...: list tags for certain cards +list cards tags...: list cards for certain tags """) @@ -133,6 +178,17 @@ if __name__ == "__main__": ctx.remove(i) elif args[0] == "untag": ctx.card_remove_tags(args[1], args[2:]) + elif args[0] == "list": + if len(args) < 3: + usage() + sys.exit(1) + if args[1] == "tags": + ctx.tags_for_cards(args[2:]) + elif args[1] == "cards": + ctx.cards_for_tags(args[2:]) + else: + usage() + sys.exit(1) else: usage() sys.exit(1) |
