<commit_before>import json, xmltodict, os, base64
from ingest import ingest_json_body, save_files, process_image, ingest_data, ingest_plain_body
from housepy import config, log, util, strings
from ingest.sighting import get_taxonomy

def parse(request):
    log.info("hydrology.parse")

    try:
        content = ingest_plain_body(request)
        data = xmltodict.parse(content)
    except Exception as e:
        log.error(log.exc(e))
        return None, "Parsing error"

    try:
        log.info("--> parsing XML")
        data = data['instance']
        log.debug(json.dumps(data, indent=4, default=lambda x: str(x)))

        feature = {'FeatureType': "hydrology", 'Delivery': "devicemagic"}
        feature['Member'] = data['@dm:submitting_user'].split(' ')[0]
        dt = util.parse_date(data['@writeTime'])
        data = data['inputs']

        feature['t_utc'] = util.timestamp(dt)

        # purge blanks
        feature = {key: value for (key, value) in feature.items() if type(value) != str or len(value.strip())}

    except Exception as e:
        log.error(log.exc(e))
        return None, "Unexpected fields"

    return feature

<commit_msg>adding hydrology<commit_after>import json, xmltodict, os, base64
from ingest import ingest_json_body, save_files, process_image, ingest_data, ingest_plain_body
from housepy import config, log, util, strings
from ingest.sighting import get_taxonomy

def parse(request):
    log.info("hydrology.parse")

    try:
        content = ingest_plain_body(request)
        data = xmltodict.parse(content)
    except Exception as e:
        log.error(log.exc(e))
        return None, "Parsing error"

    try:
        log.info("--> parsing XML")
        data = data['instance']
        log.debug(json.dumps(data, indent=4, default=lambda x: str(x)))

        feature = {'FeatureType': "hydrology", 'Delivery': "devicemagic"}
        feature.update(data['inputs'])
        feature['Member'] = data['@dm:submitting_user'].split(' ')[0]
        dt = util.parse_date(data['@writeTime'])
        feature['t_utc'] = util.timestamp(dt)

    except Exception as e:
        log.error(log.exc(e))
        return None, "Unexpected fields"

    return feature


{'fraction_non_alphanumeric': 0.1298819255222525, 'fraction_numerical': 0.0036330608537693005, 'mean_word_length': 3.1802656546489563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3675143', 'n_tokens_mistral': 715, 'n_tokens_neox': 681, 'n_words': 169}