-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyword_search.py
59 lines (47 loc) · 1.5 KB
/
keyword_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Searches the list of markdown files for entries.
"""
import json
from glob import glob
from renderers import *
ENTRIES = []
def read_config():
with open('config-sample.json') as f:
config = json.load(f)
return config
def compile_mds_in_lablog():
global ENTRIES
ENTRIES = []
config = read_config()
for repo in config['repositories']:
if repo['active']:
renderer = type_to_renderer[repo['type']]
path = repo['path']
ENTRIES += compile_paths_to_entries(path, renderer)
return ENTRIES
def search_for_keyword(keys):
keywords = keys.split()
def has_key(entry):
"""For example: key='tag:python title:string' """
k = key.split(':')
isInTitle = False
isInTags = False
isInText = False
if len(k) != 2:
isInTitle = (key.lower() in entry['title'].lower())
isInTags = (key.lower() in entry['tags'].lower())
elif k[0].lower() == 'title':
isInTitle = (k[1].lower() in entry['title'].lower())
elif k[0].lower() == 'tag':
isInTags = (k[1].lower() in entry['tags'].lower())
elif k[0].lower() == 'text':
isInText = (k[1].lower() in entry['text'].lower())
return isInTitle or isInTags or isInText
entries = ENTRIES
for key in keywords:
entries = filter(has_key, entries)
return entries
if __name__ == '__main__':
compile_mds_in_lablog()