-
Notifications
You must be signed in to change notification settings - Fork 2
/
manage.py
65 lines (48 loc) · 1.5 KB
/
manage.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
60
61
62
63
64
65
import io
import sys
import logging
from flask.ext.script import Manager
from utils import app
from utils import create_index as _create_index
from utils import delete_index as _delete_index
from utils import index_data as _index_data
from utils import query_index as _query_index
manager = Manager(app)
logging.basicConfig(level='ERROR')
@manager.command
def create_index(name=app.config['ES_INDEX_NAME']):
"""Create an elastic search index"""
_create_index(name)
@manager.command
def delete_index(name=app.config['ES_INDEX_NAME']):
"""Create an elastic search index"""
_delete_index(name)
@manager.command
def index_data(name=app.config['ES_INDEX_NAME'], path=app.config['HM_EPUB_FILES']):
"""Index magazine data"""
_index_data(name, path)
@manager.command
def reindex_data(name=app.config['ES_INDEX_NAME'], path=app.config['HM_EPUB_FILES']):
"""Query index for data"""
_delete_index(name)
_create_index(name)
_index_data(name, path)
@manager.command
def query_index(query, name=app.config['ES_INDEX_NAME']):
"""Query index for data"""
results = _query_index(name, query)
for hit in results:
source = hit['_source']
print '[{}] "{}" in {} by {}'.format(
hit['_score'],
source['title'],
source['name'],
source['author']
)
@manager.command
def runserver():
"""Runs the Flask development server i.e. app.run()"""
from main import run
run()
if __name__ == "__main__":
manager.run()