Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
3fb770d5
Verified
Commit
3fb770d5
authored
9 months ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
ENH: `datetime_parse` is new transformer function.
parent
2a7272a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!178
FIX: #96 Better error output for crawl.py script.
,
!176
misc. small changes
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caoscrawler/default_transformers.yml
+4
-1
4 additions, 1 deletion
src/caoscrawler/default_transformers.yml
src/caoscrawler/transformer_functions.py
+24
-2
24 additions, 2 deletions
src/caoscrawler/transformer_functions.py
with
28 additions
and
3 deletions
src/caoscrawler/default_transformers.yml
+
4
−
1
View file @
3fb770d5
# 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
This diff is collapsed.
Click to expand it.
src/caoscrawler/transformer_functions.py
+
24
−
2
View file @
3fb770d5
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment