import os
import time

from fofaPlug.file import save_html, save_db


def save(ret_list, file_type, file_type_name, default_file, name_file):
    str2 = str()
    for i in ret_list:
        for j in i:
            str2 += str(j) + "    "
        str2 += '\n'
    pwd = os.getcwd()
    if default_file:
        if file_type:
            if file_type_name == 'html':
                str3 = time.strftime("%Y-%m-%d-%H-%M") + ".html"
                file_type_name = pwd + '\outfile\\' + str3
                save_html.deal_file(file_type_name)
                save_html.save(ret_list,file_type_name)
                return str3
            elif file_type_name == 'db':
                str3 = time.strftime("%Y%m%d%H") + ".db"
                file_type_name = pwd + '\outfile\\' + str3
                save_db.createbd(str3)
                save_db.save(ret_list,file_type_name)
                return str3
            else:
                print('未知类型，保存默认类型')
                str3 = time.strftime("%Y-%m-%d-%H-%M") + ".txt"
                file_type_name = pwd + '\outfile\\' + str3
                with open(file_type_name, 'a', encoding='utf-8') as f:
                    f.write(str2)
                    print('write done!')
                return str3
        else:
            str3 = time.strftime("%Y-%m-%d-%H-%M") + ".txt"
            file_type_name = pwd + '\outfile\\' + str3
            # 默认txt
            with open(file_type_name, 'a', encoding='utf-8') as f:
                f.write(str2)
                print('write done!')
        return str3
    else:
        if file_type:
            if file_type_name == 'html':
                str3 = name_file + '.html'
                file_type_name = pwd + '\outfile\\' + str3
                save_html.deal_file(file_type_name)
                save_html.save(ret_list,file_type_name)
                return str3
            elif file_type_name == 'db':
                str3 = name_file + '.db'
                file_type_name = pwd + '\outfile\\' + str3
                save_db.createbd(str3)
                save_db.save(ret_list,file_type_name)
                return str3
            else:
                print('未知类型，保存默认类型')
                str3 = name_file + '.txt'
                file_type_name = pwd + '\outfile\\' + str3
                with open(file_type_name, 'a', encoding='utf-8') as f:
                    f.write(str2)
                    print('write done!')
                return str3
        else:
            str3 = name_file + '.txt'
            file_type_name = pwd + '\outfile\\' + str3
            with open(file_type_name, 'a', encoding='utf-8') as f:
                f.write(str2)
                print('write done!')
            return str3

import os
import time

from fofaPlug.file import save_html, save_db


def save(ret_list, file_type, file_type_name, default_file, name_file):
    str2 = str()
    for i in ret_list:
        for j in i:
            str2 += str(j) + "    "
        str2 += '\n'
    pwd = os.getcwd()
    if default_file:
        if file_type:
            if file_type_name == 'html':
                str3 = time.strftime("%Y-%m-%d-%H-%M") + ".html"
                file_type_name = pwd + '\outfile\\' + str3
                save_html.deal_file(file_type_name)
                save_html.save(ret_list,file_type_name)
                return str3
            elif file_type_name == 'db':
                str3 = time.strftime("%Y%m%d%H") + ".db"
                file_type_name = pwd + '\outfile\\' + str3
                save_db.createbd(str3)
                save_db.save(ret_list,file_type_name)
                return str3
            else:
                print('未知类型，保存默认类型')
                str3 = time.strftime("%Y-%m-%d-%H-%M") + ".txt"
                file_type_name = pwd + '\outfile\\' + str3
                with open(file_type_name, 'a', encoding='utf-8') as f:
                    f.write(str2)
                    print('write done!')
                return str3
        else:
            str3 = time.strftime("%Y-%m-%d-%H-%M") + ".txt"
            file_type_name = pwd + '\outfile\\' + str3
            # 默认txt
            with open(file_type_name, 'a', encoding='utf-8') as f:
                f.write(str2)
                print('write done!')
        return str3
    else:
        if file_type:
            if file_type_name == 'html':
                str3 = name_file + '.html'
                file_type_name = pwd + '\outfile\\' + str3
                save_html.deal_file(file_type_name)
                save_html.save(ret_list,file_type_name)
                return str3
            elif file_type_name == 'db':
                str3 = name_file + '.db'
                file_type_name = pwd + '\outfile\\' + str3
                save_db.createbd(str3)
                save_db.save(ret_list,file_type_name)
                return str3
            else:
                print('未知类型，保存默认类型')
                str3 = name_file + '.txt'
                file_type_name = pwd + '\outfile\\' + str3
                with open(file_type_name, 'a', encoding='utf-8') as f:
                    f.write(str2)
                    print('write done!')
                return str3
        else:
            str3 = name_file + '.txt'
            file_type_name = pwd + '\outfile\\' + str3
            with open(file_type_name, 'a', encoding='utf-8') as f:
                f.write(str2)
                print('write done!')
            return str3
