<commit_before>from datetime import datetime, timedelta

from apps.core.utils import get_ns_tag
from apps.conditions.models import Condition
from apps.domain.models import Attribute

from .models import Task


def import_tasks(tasks_node):

    nsmap = tasks_node.nsmap

    for task_node in tasks_node.iterchildren():
        task_uri = task_node[get_ns_tag('dc:uri', nsmap)].text

        try:
            task = Task.objects.get(uri=task_uri)
        except Task.DoesNotExist:
            task = Task()

        task.uri_prefix = task_uri.split('/tasks/')[0]
        task.key = task_uri.split('/')[-1]

        try:
            attribute_uri = task_node['attribute'].get(get_ns_tag('dc:uri', nsmap))
            task.attribute = Attribute.objects.get(uri=attribute_uri)
        except (AttributeError, Attribute.DoesNotExist):
            task.attribute = None

        # days, time = task_node['time_period'].text.split()
        # parsed_days = int(days)
        # parsed_time = datetime.strptime(time, '%H:%M:%S')

        # task.time_period = timedelta(days=parsed_days, hours=parsed_time.hour, minutes=parsed_time.minute, seconds=parsed_time.second)

        for element in task_node['title']:
            setattr(task, 'title_' + element.get('lang'), element.text)
        for element in task_node['text']:
            setattr(task, 'text_' + element.get('lang'), element.text)

        task.save()

        if hasattr(task_node, 'conditions'):
            for condition_node in task_node.conditions.iterchildren():
                try:
                    condition_uri = condition_node.get(get_ns_tag('dc:uri', nsmap))
                    condition = Condition.objects.get(uri=condition_uri)
                    task.conditions.add(condition)
                except Condition.DoesNotExist:
                    pass<commit_msg>cleanup<commit_after>from datetime import datetime, timedelta

from apps.core.utils import get_ns_tag
from apps.conditions.models import Condition
from apps.domain.models import Attribute

from .models import Task


def import_tasks(tasks_node):

    nsmap = tasks_node.nsmap

    for task_node in tasks_node.iterchildren():
        task_uri = task_node[get_ns_tag('dc:uri', nsmap)].text

        try:
            task = Task.objects.get(uri=task_uri)
        except Task.DoesNotExist:
            task = Task()

        task.uri_prefix = task_uri.split('/tasks/')[0]
        task.key = task_uri.split('/')[-1]

        try:
            attribute_uri = task_node['attribute'].get(get_ns_tag('dc:uri', nsmap))
            task.attribute = Attribute.objects.get(uri=attribute_uri)
        except (AttributeError, Attribute.DoesNotExist):
            task.attribute = None

        for element in task_node['title']:
            setattr(task, 'title_' + element.get('lang'), element.text)
        for element in task_node['text']:
            setattr(task, 'text_' + element.get('lang'), element.text)

        task.save()

        if hasattr(task_node, 'conditions'):
            for condition_node in task_node.conditions.iterchildren():
                try:
                    condition_uri = condition_node.get(get_ns_tag('dc:uri', nsmap))
                    condition = Condition.objects.get(uri=condition_uri)
                    task.conditions.add(condition)
                except Condition.DoesNotExist:
                    pass
{'fraction_non_alphanumeric': 0.11114404267931238, 'fraction_numerical': 0.0011855364552459987, 'mean_word_length': 2.4615384615384617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '765079', 'n_tokens_mistral': 986, 'n_tokens_neox': 958, 'n_words': 188}