__main__.py 2.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/python
# -*- coding: utf-8 -*-
#    Copyright 2014 J. Fernando Sánchez Rada - Grupo de Sistemas Inteligentes
#                                                       DIT, UPM
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
"""
Senpy is a modular sentiment analysis server. This script runs an instance of
the server.

"""
from gevent.monkey import patch_all; patch_all(thread=False)
import gevent
24
from flask import Flask
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from senpy.extensions import Senpy
import logging
import os
from gevent.wsgi import WSGIServer
import argparse

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Run a Senpy server')
    parser.add_argument('--level',
                        "-l",
                        metavar="logging_level",
                        type=str,
                        default="INFO",
                        help='Logging level')
    parser.add_argument('--debug',
                        "-d",
41
                        action='store_true',
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
                        default=False,
                        help='Run the application in debug mode')
    parser.add_argument('--host',
                        type=str,
                        default = "127.0.0.1",
                        help='Use 0.0.0.0 to accept requests from any host.')
    parser.add_argument('--port',
                        '-p',
                        type=int,
                        default = 5000,
                        help='Port to listen on.')
    parser.add_argument('--plugins-folder',
                        '-f',
                        type=str,
                        default = "plugins",
                        help='Where to look for plugins.')
    args = parser.parse_args()
    logging.basicConfig(level=getattr(logging,args.level))
    app = Flask(__name__)
    app.debug = args.debug
    sp = Senpy(app, args.plugins_folder)
    sp.activate_all()
    import logging
    http_server = WSGIServer((args.host, args.port), app)
    try:
        print "Server running on port %s:%d. Ctrl+C to quit" % (args.host,
                                                                args.port)
        http_server.serve_forever()
    except KeyboardInterrupt:
        http_server.stop()
        print "Bye!"