From 65e6b864b3251df2ca7cdbd0785f169c7b8e7ffd Mon Sep 17 00:00:00 2001 From: Bugazelle Date: Sat, 15 Feb 2020 17:05:20 +0800 Subject: [PATCH 1/2] [Feat] Allow to use the wildcard * to match all the columns --- README.md | 23 ++++++++++++------- src/ExportCsvToInflux/__version__.py | 2 +- src/ExportCsvToInflux/exporter_object.py | 4 +++- ...55\346\226\207\350\257\264\346\230\216.md" | 23 ++++++++++++------- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d9bcabf..161ca71 100644 --- a/README.md +++ b/README.md @@ -60,16 +60,23 @@ You could use `export_csv_to_influx -h` to see the help guide. -fsc, --force_string_columns, Force columns as string type, seperated as comma. Default: None ``` -> **Note 1:** You could use the library programmablly. +> **Note:** +> 1. You could pass `*` to --field_columns to match all the fields: `--field_columns=*`, `--field_columns '*'` +> 2. CSV data won't insert into influx again if no update. Use to force insert: `--force_insert_even_csv_no_update=True`, `--force_insert_even_csv_no_update True` - ``` - from ExportCsvToInflux import ExporterObject - - exporter = ExporterObject() - exporter.export_csv_to_influx(...) - ``` +## Programmatically -> **Note 2:** CSV data won't insert into influx again if no update. Use --force_insert_even_csv_no_update=True to force insert +Also, we could run the exporter programmatically. + +``` +from ExportCsvToInflux import ExporterObject + +exporter = ExporterObject() +exporter.export_csv_to_influx(...) + +# You could get the export_csv_to_influx parameter details by: +print(exporter.export_csv_to_influx.__doc__) +``` ## Sample diff --git a/src/ExportCsvToInflux/__version__.py b/src/ExportCsvToInflux/__version__.py index dccb61c..872472a 100644 --- a/src/ExportCsvToInflux/__version__.py +++ b/src/ExportCsvToInflux/__version__.py @@ -1 +1 @@ -__version__ = '0.1.21' +__version__ = '0.1.22' diff --git a/src/ExportCsvToInflux/exporter_object.py b/src/ExportCsvToInflux/exporter_object.py index a2769fa..9c93a11 100755 --- a/src/ExportCsvToInflux/exporter_object.py +++ b/src/ExportCsvToInflux/exporter_object.py @@ -82,6 +82,8 @@ def __validate_columns(csv_headers, check_columns): """Private Function: validate_columns """ if check_columns: + if len(check_columns) == 1 and check_columns[0] == '*': + return csv_headers validate_check_columns = all(check_column in csv_headers for check_column in check_columns) if validate_check_columns is False: print('Warning: Not all columns {0} in csv headers {1}. ' @@ -150,7 +152,7 @@ def export_csv_to_influx(self, :param db_name: the influx db name :param db_measurement: the measurement in a db :param time_column: the time columns (default timestamp) - :param tag_columns: the tag columns + :param tag_columns: the tag columns (default None) :param time_format: the time format (default %Y-%m-%d %H:%M:%S) :param field_columns: the filed columns :param delimiter: the csv delimiter (default comma) diff --git "a/\344\270\255\346\226\207\350\257\264\346\230\216.md" "b/\344\270\255\346\226\207\350\257\264\346\230\216.md" index f9f8d09..1004db7 100644 --- "a/\344\270\255\346\226\207\350\257\264\346\230\216.md" +++ "b/\344\270\255\346\226\207\350\257\264\346\230\216.md" @@ -61,16 +61,23 @@ pip install ExportCsvToInflux -fsc, --force_string_columns, 强制将列的类型转换成string类型, 使用英文逗号 ',' 作为分隔符. 默认: None ``` -> **注意点 1:** 可以使用代码调用 +> **注意:** +> 1. --field_columns 可以使用通配符 `*`,来匹配所有的列: `--field_columns=*`, `--field_columns '*'` +> 2. 如果检查到csv文件没有更新, 数据不会重复插入到数据库. 可以使用强制插入: `--force_insert_even_csv_no_update=True`, `--force_insert_even_csv_no_update True` - ``` - from ExportCsvToInflux import ExporterObject - - exporter = ExporterObject() - exporter.export_csv_to_influx(...) - ``` +## 使用代码调用 -> **注意点 2:** 如果检查到csv文件没有更新, 数据不会重复插入到数据库. 可以使用 **--force_insert_even_csv_no_update=True** 强制插入 +可以使用代码直接调用 + +``` +from ExportCsvToInflux import ExporterObject + +exporter = ExporterObject() +exporter.export_csv_to_influx(...) + +# 更多关于export_csv_to_influx的参数细节: +print(exporter.export_csv_to_influx.__doc__) +``` ## 示例 From 72d6a46e37f01fc35225c7a6b503ed207982188e Mon Sep 17 00:00:00 2001 From: Bugazelle Date: Sat, 15 Feb 2020 17:11:13 +0800 Subject: [PATCH 2/2] [Fix] Fix pypi format issue --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 976a695..7543662 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ def readme(): with open('README.md') as f: long_description = f.read() - index = long_description.find('```\n\n> **Note 1:**') + index = long_description.find('```\n\n> **Note:**') long_description = long_description[:index] long_description = long_description.replace('## Install', '**Install**') long_description = long_description.replace('## Features', '**Features**')