Skip to content

Commit 423c82f

Browse files
author
George K. Thiruvathukal
committed
add --get-all-tags and --get-all-mentions to zfind command
1 parent d39210b commit 423c82f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

zettelgeist/zdb.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ def fts_search(self, term_list):
129129
def fts_query(self, prepared_sql):
130130
return self.cursor.execute(prepared_sql)
131131

132+
def get_tags_generator(self):
133+
Q = "select distinct(tag) from tags"
134+
for row in self.cursor.execute(Q):
135+
yield(row['tag'])
136+
137+
def get_tags_list(self):
138+
gen = self.get_tags_generator()
139+
return list(gen)
140+
141+
def get_mentions_generator(self):
142+
Q = "select distinct(mention) from mentions"
143+
for row in self.cursor.execute(Q):
144+
yield(row['mention'])
145+
146+
def get_mentions_list(self):
147+
gen = self.get_mentions_generator()
148+
return list(gen)
149+
132150
def done(self):
133151
self.conn.commit()
134152
self.conn.close()

zettelgeist/zfind.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def get_argparse():
3535
parser.add_argument(
3636
'--stats', help="write statistics and parameters to filename", default=None)
3737

38+
parser.add_argument(
39+
'--get-all-tags', help="show all tags in this database (disables all other options)", action="store_true", default=False)
40+
41+
parser.add_argument(
42+
'--get-all-mentions', help="show all mentions in this database (disables all other options)", action="store_true", default=False)
43+
3844
return parser
3945

4046

@@ -43,6 +49,15 @@ def main():
4349
args = parser.parse_args()
4450
argsd = vars(args)
4551

52+
db = zdb.get(args.database)
53+
if args.get_all_tags:
54+
print('\n'.join(db.get_tags_list()))
55+
exit(0)
56+
57+
if args.get_all_mentions:
58+
print('\n'.join(db.get_mentions_list()))
59+
exit(0)
60+
4661
if args.query_prompt:
4762
input_line = input("zfind> ")
4863
elif args.query_file:
@@ -56,7 +71,6 @@ def main():
5671

5772
if input_line:
5873
ast = zquery.compile(input_line)
59-
db = zdb.get(args.database)
6074
gen = db.fts_query(ast[0])
6175
else:
6276
print("Warning: Query could not be loaded via --query, --query-file, or --query-prompt")

0 commit comments

Comments
 (0)