async def run():
    server_setting = {'host': {'setting': 'host', 'default': '0.0.0.0'}, 'port': {'setting': 'port', 'default': '3000'}, 'lang': {'setting': 'lang', 'default': 'ko-KR', 'list': ['ko-KR', 'en-US']}, 'encode': {'setting': 'encode', 'default': 'pbkdf2-sha512', 'list': ['sha3', 'sha256', 'pbkdf2-sha512']}}
    try:
        async with aiofiles.open('data/setting.json', encoding='utf8') as f:
            setting_data = json.loads((await f.read()))
        if ((not 'db_type') and 'db_name' and 'host' and ('port' in setting_data)):
            try:
                os.remove('data/setting.json')
            except:
                print('Error : Please delete data/setting.json')
                raise
        else:
            print(('db_type : ' + setting_data['db_type']))
            print(('db_name : ' + setting_data['db_name']))
            print('\n', end='')
            print(('host : ' + setting_data['host']))
            print(('port : ' + setting_data['port']))
    except:
        setting_json = ['sqlite', '', '', '']
        db_type = ['sqlite']
        print('db_type : sqlite')
        print('db_name : ', end='')
        setting_json[1] = str(input())
        if (setting_json[1] == ''):
            setting_json[1] = 'data'
        print('\n', end='')
        print((('host (' + server_setting['host']['default']) + ') : '), end='')
        setting_json[2] = str(input())
        if (setting_json[2] == ''):
            setting_json[2] = server_setting['host']['default']
        print((('port (' + server_setting['port']['default']) + ') : '), end='')
        setting_json[3] = str(input())
        if (setting_json[3] == ''):
            setting_json[3] = server_setting['port']['default']
        async with aiofiles.open('data/setting.json', 'w', encoding='utf8') as f:
            (await f.write((((((((('{ "db_name" : "' + setting_json[1]) + '", "db_type" : "') + setting_json[0]) + '", "host" : "') + setting_json[2]) + '", "port" : "') + setting_json[3]) + '" }')))
    async with aiofiles.open('data/setting.json', encoding='utf8') as f:
        setting_data = json.loads((await f.read()))
        db = (await aiosqlite.connect((setting_data['db_name'] + '.db')))
    db_create = {}
    db_create['table'] = ['doc', 'doc_cac', 'doc_his', 'rec_dis', 'rec_ban', 'rec_log', 'mbr', 'mbr_set', 'mbr_log', 'ban', 'dis', 'dis_log', 'acl', 'backlink', 'wiki_set', 'list_per', 'list_fil', 'html_fil', 'list_alarm', 'list_watch', 'list_inter']
    for i in db_create['table']:
        try:
            (await db.execute((('select test from ' + i) + ' limit 1')))
        except:
            try:
                (await db.execute((('create table ' + i) + '(test longtext)')))
            except:
                (await db.execute((('alter table ' + i) + " add test longtext default ''")))
    db_setup = 0
    try:
        db_ver = (await db.execute('select data from wiki_set where name = "db_ver"'))
        db_ver = (await db_ver.fetchall())
        if (not db_ver):
            db_setup = 1
        elif (int(version_load['main']['renew_count']) > int(db_ver[0][0])):
            db_setup = 1
    except:
        db_setup = 1
    if (db_setup != 0):
        db_create['doc'] = ['title', 'data']
        db_create['doc_cac'] = ['title', 'data']
        db_create['doc_his'] = ['id', 'title', 'data', 'date', 'ip', 'send', 'leng', 'hide', 'type']
        db_create['rec_dis'] = ['title', 'sub', 'date', 'band', 'stop', 'agree']
        db_create['rec_ban'] = ['block', 'end', 'today', 'blocker', 'why', 'band']
        db_create['rec_log'] = ['who', 'what', 'time']
        db_create['mbr'] = ['id', 'pw', 'acl', 'date', 'email']
        db_create['mbr_set'] = ['name', 'id', 'data']
        db_create['mbr_log'] = ['name', 'ip', 'ua', 'today', 'sub']
        db_create['ban'] = ['block', 'end', 'why', 'band', 'login']
        db_create['dis'] = ['doc', 'title', 'id', 'state', 'date', 'agree']
        db_create['dis_log'] = ['id', 'data', 'date', 'ip', 'block', 'top', 'code', 'doc']
        db_create['acl'] = ['title', 'decu', 'dis', 'view', 'why']
        db_create['backlink'] = ['title', 'link', 'type']
        db_create['wiki_set'] = ['name', 'data', 'coverage']
        db_create['list_per'] = ['name', 'acl']
        db_create['list_fil'] = ['name', 'regex', 'sub']
        db_create['html_fil'] = ['html', 'kind', 'plus']
        db_create['list_alarm'] = ['name', 'data', 'date']
        db_create['list_watch'] = ['user', 'title']
        db_create['list_inter'] = ['title', 'link', 'icon']
        for create_table in db_create['table']:
            for create in db_create[create_table]:
                try:
                    (await db.execute((((('select ' + create) + ' from ') + create_table) + ' limit 1')))
                except:
                    (await db.execute((((('alter table ' + create_table) + ' add ') + create) + " longtext default ''")))
                try:
                    (await db.execute((((((((('create index index_' + create_table) + '_') + create) + ' on ') + create_table) + '(') + create) + ')')))
                except:
                    pass
    (await db.execute('delete from wiki_set where name = "db_ver"'))
    (await db.execute('insert into wiki_set (name, data) values (?, ?)', ['db_ver', version_load['main']['renew_count']]))
    (await db.commit())
    first_setup = (await db.execute('select data from wiki_set where name = "lang"'))
    first_setup = (await first_setup.fetchall())
    if (not first_setup):
        lang = ((server_setting['lang']['list'][0] + ', ') + server_setting['lang']['list'][1])
        print((((('lang [' + lang) + '] (') + server_setting['lang']['default']) + ') : '), end='')
        setting_lang = str(input())
        if (setting_lang == ''):
            setting_lang = server_setting['lang']['default']
        (await db.execute('insert into wiki_set (name, data) values (?, ?)', ['lang', setting_lang]))
        encode = ((((server_setting['encode']['list'][0] + ', ') + server_setting['encode']['list'][1]) + ', ') + server_setting['encode']['list'][2])
        print((((('encode [' + encode) + '] (') + server_setting['encode']['default']) + ') : '), end='')
        setting_encode = str(input())
        if (setting_encode == ''):
            setting_encode = server_setting['encode']['default']
        (await db.execute('insert into wiki_set (name, data) values (?, ?)', ['encode', setting_encode]))
        (await db.commit())
    else:
        encode_check = (await db.execute('select data from wiki_set where name = "encode"'))
        encode_check = (await encode_check.fetchall())
        print(('lang : ' + first_setup[0][0]))
        print(('encode : ' + encode_check[0][0]))
    print('\n', end='')
async def run():
    server_setting = {'host': {'setting': 'host', 'default': '0.0.0.0'}, 'port': {'setting': 'port', 'default': '3000'}, 'lang': {'setting': 'lang', 'default': 'ko-KR', 'list': ['ko-KR', 'en-US']}, 'encode': {'setting': 'encode', 'default': 'pbkdf2-sha512', 'list': ['sha3', 'sha256', 'pbkdf2-sha512']}}
    try:
        async with aiofiles.open('data/setting.json', encoding='utf8') as f:
            setting_data = json.loads((await f.read()))
        if ((not 'db_type') and 'db_name' and 'host' and ('port' in setting_data)):
            try:
                os.remove('data/setting.json')
            except:
                print('Error : Please delete data/setting.json')
                raise
        else:
            print(('db_type : ' + setting_data['db_type']))
            print(('db_name : ' + setting_data['db_name']))
            print('\n', end=)
            print(('host : ' + setting_data['host']))
            print(('port : ' + setting_data['port']))
    except:
        setting_json = ['sqlite', , , ]
        db_type = ['sqlite']
        print('db_type : sqlite')
        print('db_name : ', end=)
        setting_json[1] = str(input())
        if (setting_json[1] == ):
            setting_json[1] = 'data'
        print('\n', end=)
        print((('host (' + server_setting['host']['default']) + ') : '), end=)
        setting_json[2] = str(input())
        if (setting_json[2] == ):
            setting_json[2] = server_setting['host']['default']
        print((('port (' + server_setting['port']['default']) + ') : '), end=)
        setting_json[3] = str(input())
        if (setting_json[3] == ):
            setting_json[3] = server_setting['port']['default']
        async with aiofiles.open('data/setting.json', 'w', encoding='utf8') as f:
            (await f.write((((((((('{ "db_name" : "' + setting_json[1]) + '", "db_type" : "') + setting_json[0]) + '", "host" : "') + setting_json[2]) + '", "port" : "') + setting_json[3]) + '" }')))
    async with aiofiles.open('data/setting.json', encoding='utf8') as f:
        setting_data = json.loads((await f.read()))
        db = (await aiosqlite.connect((setting_data['db_name'] + '.db')))
    db_create = {}
    db_create['table'] = ['doc', 'doc_cac', 'doc_his', 'rec_dis', 'rec_ban', 'rec_log', 'mbr', 'mbr_set', 'mbr_log', 'ban', 'dis', 'dis_log', 'acl', 'backlink', 'wiki_set', 'list_per', 'list_fil', 'html_fil', 'list_alarm', 'list_watch', 'list_inter']
    for i in db_create['table']:
        try:
            (await db.execute((('select test from ' + i) + ' limit 1')))
        except:
            try:
                (await db.execute((('create table ' + i) + '(test longtext)')))
            except:
                (await db.execute((('alter table ' + i) + " add test longtext default ")))
    db_setup = 0
    try:
        db_ver = (await db.execute('select data from wiki_set where name = "db_ver"'))
        db_ver = (await db_ver.fetchall())
        if (not db_ver):
            db_setup = 1
        elif (int(version_load['main']['renew_count']) > int(db_ver[0][0])):
            db_setup = 1
    except:
        db_setup = 1
    if (db_setup != 0):
        db_create['doc'] = ['title', 'data']
        db_create['doc_cac'] = ['title', 'data']
        db_create['doc_his'] = ['id', 'title', 'data', 'date', 'ip', 'send', 'leng', 'hide', 'type']
        db_create['rec_dis'] = ['title', 'sub', 'date', 'band', 'stop', 'agree']
        db_create['rec_ban'] = ['block', 'end', 'today', 'blocker', 'why', 'band']
        db_create['rec_log'] = ['who', 'what', 'time']
        db_create['mbr'] = ['id', 'pw', 'acl', 'date', 'email']
        db_create['mbr_set'] = ['name', 'id', 'data']
        db_create['mbr_log'] = ['name', 'ip', 'ua', 'today', 'sub']
        db_create['ban'] = ['block', 'end', 'why', 'band', 'login']
        db_create['dis'] = ['doc', 'title', 'id', 'state', 'date', 'agree']
        db_create['dis_log'] = ['id', 'data', 'date', 'ip', 'block', 'top', 'code', 'doc']
        db_create['acl'] = ['title', 'decu', 'dis', 'view', 'why']
        db_create['backlink'] = ['title', 'link', 'type']
        db_create['wiki_set'] = ['name', 'data', 'coverage']
        db_create['list_per'] = ['name', 'acl']
        db_create['list_fil'] = ['name', 'regex', 'sub']
        db_create['html_fil'] = ['html', 'kind', 'plus']
        db_create['list_alarm'] = ['name', 'data', 'date']
        db_create['list_watch'] = ['user', 'title']
        db_create['list_inter'] = ['title', 'link', 'icon']
        for create_table in db_create['table']:
            for create in db_create[create_table]:
                try:
                    (await db.execute((((('select ' + create) + ' from ') + create_table) + ' limit 1')))
                except:
                    (await db.execute((((('alter table ' + create_table) + ' add ') + create) + " longtext default ")))
                try:
                    (await db.execute((((((((('create index index_' + create_table) + '_') + create) + ' on ') + create_table) + '(') + create) + ')')))
                except:
                    pass
    (await db.execute('delete from wiki_set where name = "db_ver"'))
    (await db.execute('insert into wiki_set (name, data) values (?, ?)', ['db_ver', version_load['main']['renew_count']]))
    (await db.commit())
    first_setup = (await db.execute('select data from wiki_set where name = "lang"'))
    first_setup = (await first_setup.fetchall())
    if (not first_setup):
        lang = ((server_setting['lang']['list'][0] + ', ') + server_setting['lang']['list'][1])
        print((((('lang [' + lang) + '] (') + server_setting['lang']['default']) + ') : '), end=)
        setting_lang = str(input())
        if (setting_lang == ):
            setting_lang = server_setting['lang']['default']
        (await db.execute('insert into wiki_set (name, data) values (?, ?)', ['lang', setting_lang]))
        encode = ((((server_setting['encode']['list'][0] + ', ') + server_setting['encode']['list'][1]) + ', ') + server_setting['encode']['list'][2])
        print((((('encode [' + encode) + '] (') + server_setting['encode']['default']) + ') : '), end=)
        setting_encode = str(input())
        if (setting_encode == ):
            setting_encode = server_setting['encode']['default']
        (await db.execute('insert into wiki_set (name, data) values (?, ?)', ['encode', setting_encode]))
        (await db.commit())
    else:
        encode_check = (await db.execute('select data from wiki_set where name = "encode"'))
        encode_check = (await encode_check.fetchall())
        print(('lang : ' + first_setup[0][0]))
        print(('encode : ' + encode_check[0][0]))
    print('\n', end=)