Пример #1
0
def get_edi_code_from_gosi(xl_file):
	
	edis = Listorm()
	re_compile_edi = re.compile('[A-Z\d]\d{8}')
	wb = xlrd.open_workbook(xl_file)
	for sheet_index in range(wb.nsheets):
		sheet = wb.sheet_by_index(sheet_index)
		
		for r in range(sheet.nrows):
			for cell in sheet.row(r):
				for edi in re_compile_edi.findall(str(cell.value)):
					edis.append({'시트이름': sheet.name, 'EDI코드':edi})
	return Listorm(edis)
Пример #2
0
class CollectStorage(object):
    def __init__(self,
                 filepath,
                 max_object_list_length=MAX_OBJECT_LIST_LENGTH):
        self.path = filepath
        self.max_object_list_length = max_object_list_length
        self._get_or_create_dir(self.path)
        self._load()

    def _get_or_create_dir(self, path):
        try:
            if os.path.isdir(path):
                os.makedirs(path)
            else:
                path = os.path.dirname(path)
                os.makedirs(path)
        except:
            return

    def _load(self):
        if os.path.isfile(self.path):
            with open(self.path) as fp:
                self.object_list = Listorm(json.loads(fp.read()))
        else:
            self.object_list = Listorm()

    def save(self, object=None, commit=True):
        if object:
            self.object_list.append(object)
        if commit:
            with open(self.path, 'w') as fp:
                object_list = self.object_list[-self.max_object_list_length:]
                data = json.dumps(object_list, indent=4)
                fp.write(data)
            return
        return self.object_list

    def delete(self, slug):
        self.object_list = self.object_list.filter(
            lambda row: row.slug != slug)
        self.save()

    def clear(self):
        self.object_list = Listorm()
        self.save()

    def get(self, slug):
        return self.object_list.filterand(slug=slug).first

    def get_object_list(self):
        return Listorm(self.object_list[::-1])

    def get_latest(self, **kwargs):
        latest = self.object_list
        for key, val in kwargs.items():
            if key == 'date':
                date = time_to_normstr(val)
                latest = latest.filterand(date=date)
            elif key in ['types', 'kinds', 'wards']:
                latest = latest.filter(lambda row: set(row[key]) <= set(val))
        latest = latest.top('seq')
        return latest