Skip to content
Snippets Groups Projects
Verified Commit 3fb770d5 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: `datetime_parse` is new transformer function.

parent 2a7272a2
No related branches found
No related tags found
2 merge requests!178FIX: #96 Better error output for crawl.py script.,!176misc. small changes
# Lookup table for matching functions and cfood yaml node names.
submatch:
package: caoscrawler.transformer_functions
......@@ -9,3 +9,6 @@ split:
replace:
package: caoscrawler.transformer_functions
function: replace
datetime_parse:
package: caoscrawler.transformer_functions
function: datetime_parse
......@@ -20,9 +20,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Definition of default transformer functions.
See https://docs.indiscale.com/caosdb-crawler/converters.html#transform-functions for more
information.
"""
Defnition of default transformer functions.
"""
import datetime
import re
from typing import Any
......@@ -61,3 +66,20 @@ def replace(in_value: Any, in_parameters: dict):
if not isinstance(in_value, str):
raise RuntimeError("must be string")
return in_value.replace(in_parameters['remove'], in_parameters['insert'])
def datetime_parse(in_value: str, params: dict):
"""Transform text so that it is formatted in a way that LinkAhead can understand it.
Parameters
==========
- datetime_format: str, optional
A format string using the ``datetime`` specificaton:
https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
"""
fmt_default = "%Y-%m-%dT%H:%M:%S"
fmt = params.get("datetime_format", fmt_default)
dt_str = datetime.datetime.strptime(in_value, fmt).strftime(fmt_default)
return dt_str
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment