-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_flask.py
61 lines (50 loc) · 1.47 KB
/
api_flask.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Albatros API
REST interface for Albatros
@category Utility
@version $ID: 1.1.1, 2016-05-05 17:00:00 CST $;
@author KMR
@licence GNU GPL v.3
"""
import os, yaml
import time, sys
from api import interface
from daemon import daemon
from flask import Flask, request, jsonify, redirect
class AlbatrosDaemon(daemon.Daemon):
def __init__(self, pidfile='/tmp/albatros.pid'):
super(AlbatrosDaemon, self).__init__(pidfile)
def run(self):
fa = FlaskApp()
fa.run()
class FlaskApp:
DIR = os.path.dirname(os.path.realpath(__file__))
conf = yaml.safe_load(open("{}/flask.cfg".format(DIR)))
app = Flask(__name__)
address_interface = interface.interface()
def run(self):
@self.app.route('search')
def search():
return address_interface.search()
@self.app.route('get')
def get():
return address_interface.get()
self.app.run(host=self.conf['HOST'], port=self.conf['PORT'])
if __name__ == "__main__":
daemon = AlbatrosDaemon()
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print "Unknown command"
sys.exit(2)
sys.exit(0)
else:
print "usage: %s start|stop|restart" % sys.argv[0]
sys.exit(2)