Skip to content
Snippets Groups Projects
Commit ec13ec8f authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

update

parent 049ed856
No related branches found
No related tags found
No related merge requests found
......@@ -31,15 +31,15 @@ from datetime import datetime
import caosdb as db
from caosdb.exceptions import TransactionError
from something import get_entity
#from something import get_entity
class AbstractCFood(object):
def __init__(self, pattern):
self.pattern = re.compile(pattern)
def treat_match(self, filename, match):
entities = self.create_identifiables(filename, match)
def treat_match(self, crawled_file, match):
entities = self.create_identifiables(crawled_file, match)
for key, ent in entities.items():
existing = AbstractCFood.find_existing(ent)
......@@ -53,12 +53,12 @@ class AbstractCFood(object):
print(key, "exists")
entities[key] = existing
self.update_identifiables(entities, filename, match)
self.update_identifiables(entities, crawled_file, match)
def create_identifiables(self, filename, match):
def create_identifiables(self, crawled_file, match):
raise NotImplementedError()
def update_identifiables(self, entities, filename, match):
def update_identifiables(self, entities, crawled_file, match):
raise NotImplementedError()
@staticmethod
......@@ -92,22 +92,6 @@ class AbstractCFood(object):
return r
class ExampleCFood(AbstractCFood):
def create_identifiables(self, filename, match):
entities = {}
entities["exp"] = db.Record()
#import IPython
# IPython.embed()
entities["exp"].add_parent(name="Experiment")
entities["exp"].add_property(name="species", value=match.group)
return entities
def update_identifiables(self, entities, filename, match):
entities["exp"].add_property(name="date",
value=datetime.today().isoformat())
db.Container().extend(entities.values).update()
def get_parser():
parser = argparse.ArgumentParser(description=__doc__,
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#!/usr/bin/env python
# encoding: utf-8
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# 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/>.
#
# ** end header
#
"""does something"""
import argparse
......@@ -7,8 +29,6 @@ from argparse import RawTextHelpFormatter
import caosdb as db
from cfood import CFood
class Crawler(object):
def __init__(self, food):
......@@ -31,17 +51,3 @@ class Crawler(object):
cfood.treat_match(crawled_file.path, match)
def get_parser():
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
return parser
if __name__ == "__main__":
parser = get_parser()
args = parser.parse_args()
f = CFood(pattern="(.*)to(.*)")
c = Crawler(food=[f])
c.crawl(["path/to/file"])
......@@ -26,6 +26,7 @@
import math
import sys
from argparse import ArgumentParser
import argparse
import caosdb as db
......
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