Esempio n. 1
0
def write_xls_content(table_name, rows):
    wbk = xlwt.Workbook()
    # 新建一个名为Sheet1的excel sheet。此处的cell_overwrite_ok =True是为了能对同一个单元格重复操作。
    sheet = wbk.add_sheet('Sheet1', cell_overwrite_ok=True)
    # 获取当前日期,得到一个datetime对象如:(2016, 8, 9, 23, 12, 23, 424000)
    # 遍历result中的没个元素。
    for i in range(len(rows)):
        # 对result的每个子元素作遍历,
        for j in range(len(rows[i])):
            # 将每一行的每个元素按行号i,列号j,写入到excel中。
            sheet.write(i, j, rows[i][j])
    # 以传递的name+当前日期作为excel名称保存。
    table_name = table_name.replace(' ', '_')
    wbk.save(combine_file_path('gen/export.xls'))
    shutil.move(combine_file_path('gen/export.xls'), combine_file_path('gen/' + table_name))
Esempio n. 2
0
def file_download():
    file_name = request.args.get("fileName")
    response = make_response(send_file(combine_file_path('gen/' + file_name)))
    response.headers[
        "Content-Disposition"] = "attachment; filename={};".format('export.' +
                                                                   'xls')
    return response
Esempio n. 3
0
def char_to_image(char):
    """
    char
    """
    des_dir = combine_file_path('resource/char') + '/'
    for font in FONT_OBJECTS:
        size = font.getsize(char)
        scene_text = Image.new('RGBA', size)
        draw = ImageDraw.Draw(scene_text)
        draw.text((0, 0), char, font=font)
        scene_text = np.array(scene_text)
        start_index = 0
        for i in range(30):
            if scene_text[i, :, :].max() == 0:
                start_index = i
            else:
                break
        new_area = scene_text[start_index:, :, :]
        write_image(des_dir + char + '_' + get_uuid_str() + '.jpg',
                    255 - new_area)
Esempio n. 4
0
   date:          2020/8/15
-------------------------------------------------
   Change Activity:
                   2020/8/15:
-------------------------------------------------
"""
from llib.cv_utility.image_opt_utility import write_image
from llib.file_utility.file_path_utility import combine_file_path, get_all_files_under_directory
from PIL import Image, ImageDraw, ImageFont

from llib.random_utility.random_utility import fetch_item_from_list
import numpy as np

from llib.random_utility.uuid_utility import get_uuid_str

TTF_PATHS = get_all_files_under_directory(combine_file_path('resource/font'))
FONT_SIZE = 44


def __load_font_objects():
    font_lst = []
    for path in TTF_PATHS:
        font = ImageFont.truetype(path, FONT_SIZE)
        font_lst.append(font)
    return font_lst


FONT_OBJECTS = __load_font_objects()


def char_to_image(char):
Esempio n. 5
0
def main():
    xls_path = combine_file_path('resource/1.XLS')
    content = read_xls_content(xls_path)
Esempio n. 6
0
   File Name:     log_util
   Description :
   Author :       'li'
   date:          2020/3/30
-------------------------------------------------
   Change Activity:
                   2020/3/30:
-------------------------------------------------
"""
import datetime
import time

from llib.log_utility.time_format import TimeFormat
from llib.file_utility.file_path_utility import combine_file_path, create_dir

LOG_DIR = combine_file_path('log/')
create_dir(LOG_DIR)


def get_launch_time():
    return TimeFormat.date_stamp_to_datetime(time.time()).replace(' ',
                                                                  '.').replace(
                                                                      ':', '-')


LAUNCH_TIME = get_launch_time()

LOG_TMP_PATH = 'log/log-%s.log' % LAUNCH_TIME
LOG_PATH = LOG_DIR = combine_file_path(LOG_TMP_PATH)

Esempio n. 7
0
-------------------------------------------------
   Change Activity:
                   2020/8/15:
-------------------------------------------------
"""
import os

from llib.cv_utility.image_opt_utility import read_image, write_image
from llib.cv_utility.image_preprocess.jittering_methods import *
from llib.cv_utility.image_resize_utility import ImageUtility
from llib.file_utility.file_path_utility import combine_file_path, get_all_files_under_directory
import numpy as np

from llib.random_utility.random_utility import fetch_item_from_list

CHAR_DIR = combine_file_path('resource/char')


def __load_char_mapping():
    """

    """
    char_mapping = {}
    char_paths = get_all_files_under_directory(CHAR_DIR)
    for p in char_paths:
        _, name = os.path.split(p)
        label = name.split('_')[0]
        img = read_image(p)
        if label not in char_mapping:
            char_mapping[label] = []
        char_mapping[label] = img