-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (45 loc) · 1.89 KB
/
main.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
import argparse
# from flask import Flask
# from gevent.pywsgi import WSGIServer
from json import dumps
# from lib import sdk
from lib.helpers import logging
from lib.controllers.bps import Bps
from lib.helpers.TypeEnums import Sosial_Kependudukan, Ekonomi_Perdagangan, Pertanian_Pertambangan
import os
def loop_write(main: str, options: any, *args) -> None:
for topic in options:
data: str = dumps(bps.execute(topic.value))
path_output: str = f'data/{main}/{topic.name}.json'
if(not os.path_output.exists('/'.join(path_output.split('/')[:-1]))):
os.makedirs('/'.join(path_output.split('/')[:-1]))
with open(path_output, 'w') as file:
file.write(data)
if __name__ == "__main__":
argp = argparse.ArgumentParser()
argp.add_argument("--topic", '-t', type=str)
argp.add_argument("--server", '-s', type=bool)
argp.add_argument("--port", '-p', type=int, default=4444)
args = argp.parse_args()
# if(args.server):
# class App(Flask):
# def __init__(self, import_name, **kwargs):
# super().__init__(import_name)
# app = App(__name__)
# app.register_blueprint(sdk)
# application = app
# logging.info(f"listening -> http://localhost:{args.port} ....")
# logging.info(f"swagger-ui -> http://localhost:{args.port}/docs ....")
# http_server = WSGIServer(("localhost", args.port), application)
# http_server.serve_forever()
if(args.topic):
from lib.services import Bps
bps: Bps = Bps()
match(args.topic.upper()):
case 'SOSIAL':
loop_write('Sosial', Sosial_Kependudukan)
case 'EKONOMI':
loop_write('Ekonomi', Ekonomi_Perdagangan)
case 'PERTANIAN':
loop_write('Pertanian', Pertanian_Pertambangan)
logging.info("admitted smoothly")