예제 #1
0
파일: file.py 프로젝트: cocoa-maemae/cliboa
    def execute(self, *args):
        file = super().execute()
        valid = EssentialParameters(self.__class__.__name__,
                                    [self._columns, self._formatter])
        valid()

        _, ext = os.path.splitext(file)
        if ext == ".csv":
            delimiter = ","
        elif ext == ".tsv":
            delimiter = "\t"

        with codecs.open(file, mode="r",
                         encoding=self._encoding) as fi, codecs.open(
                             self._dest_path,
                             mode="w",
                             encoding=self._encoding) as fo:
            reader = csv.DictReader(fi, delimiter=delimiter)
            writer = csv.DictWriter(fo, reader.fieldnames)
            writer.writeheader()
            date_util = DateUtil()
            for row in reader:
                for column in self._columns:
                    r = row.get(column)
                    if not r:
                        continue
                    row[column] = date_util.convert_date_format(
                        r, self._formatter)
                writer.writerow(row)
            fo.flush()
        self._logger.info("Finish %s" % self.__class__.__name__)
예제 #2
0
    def test_get_logger(self):

        res = DateUtil().convert_date_format("2019/1/01 00:00:00",
                                             "%Y-%m-%d %H:%M:%S")
        assert res == "2019-01-01 00:00:00"

        res = DateUtil().convert_date_format("2019/1/01 00:00:00",
                                             "%Y-%m-%d %H:00")
        assert res == "2019-01-01 00:00"

        res = DateUtil().convert_date_format("2019-01-01 00:00:00",
                                             "%Y%m%d%H%M%S")
        assert res == "20190101000000"