-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
36 lines (29 loc) · 954 Bytes
/
server.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
from flask import Flask
from collections import OrderedDict
from json import dumps, loads
app = Flask(__name__)
from flask_cors import CORS
import os
import importlib
CORS(app)
CONFIG = None
PARSERS = None
def parseConfig():
global CONFIG, PARSERS
parentDir = os.path.dirname(os.path.realpath(__file__))
configFilePath = os.path.join(parentDir, "config.json")
parsersConfigFilePath = os.path.join(parentDir, "parsers", "parsers.json")
with open(configFilePath, "r") as fh:
CONFIG = loads(fh.read())
with open(parsersConfigFilePath, "r") as fh:
PARSERS = loads(fh.read())
parseConfig()
selectedParserModule= PARSERS[CONFIG["vendor"]]
module = importlib.import_module("parsers." + selectedParserModule)
parser = getattr(module, selectedParserModule )()
@app.route("/")
def getData():
global parser, CONFIG
result = parser.parse(CONFIG["url"])
return dumps(result)
app.run(debug=True)