<commit_before># -*- coding: utf-8 -*-
import re

import requests
from bs4 import BeautifulSoup


HIDDEN_TOKEN_NAME = 'dmrFormToken'
SEARCH_FORM_NAME = 'kerne_vis_koeretoej{actionForm.soegeord}'

CAPITALIZED_BRANDS = ['VW', 'BMW']


def get_car_details(license_plate, details=False):
    session = requests.Session()

    token = _get_token(session)
    if not token:
        #Bad result - skat probably down
        return {
            "error": 500,
            "message": "Scraper not finding expected HTML structure. (Token)"
        }

    payload = {
        HIDDEN_TOKEN_NAME: token,
        SEARCH_FORM_NAME: license_plate
    }

    car_found, car_info = _min_car_info(session, payload)

    if car_found and details:
        car_info.update(_technical_car_info(session))
        car_info.update(_insurance_car_info(session))

    return car_info


def _get_token(session):
    """Gets the value of the hidden search form token."""
    response = session.get('https://motorregister.skat.dk/dmr-front/appmanager/skat/dmr?_nfls=false&_nfpb=true&_pageLabel=vis_koeretoej_side')

    soup = BeautifulSoup(response.content)

    try:
        return soup.find('input', attrs={'name': 'dmrFormToken'})['value']
    except (TypeError, KeyError):
        return None<commit_msg>Added a method that will get the text value<commit_after># -*- coding: utf-8 -*-
import re

import requests
from bs4 import BeautifulSoup, element

HIDDEN_TOKEN_NAME = 'dmrFormToken'
SEARCH_FORM_NAME = 'kerne_vis_koeretoej{actionForm.soegeord}'

CAPITALIZED_BRANDS = ['VW', 'BMW']


def _get_text_value(content, *args):
    """Returns the value inside the content"""
    try:
        value = content
        for index in list(args):
            value = value[index]

        if value != content and type(value) == element.Tag:
            return True, value.text

    except (IndexError, KeyError, AttributeError):
        return False, None
    return True, None


def get_car_details(license_plate, details=False):
    session = requests.Session()

    token = _get_token(session)
    if not token:
        # Bad result - skat probably down
        return {
            "error": 500,
            "message": "Scraper not finding expected HTML structure. (Token)"
        }

    payload = {
        HIDDEN_TOKEN_NAME: token,
        SEARCH_FORM_NAME: license_plate
    }

    car_found, car_info = _min_car_info(session, payload)

    if car_found and details:
        car_info.update(_technical_car_info(session))
        car_info.update(_insurance_car_info(session))

    return car_info


def _get_token(session):
    """Gets the value of the hidden search form token."""
    response = session.get('https://motorregister.skat.dk/dmr-front/appmanager/skat/dmr?_nfls=false&_nfpb=true&_pageLabel=vis_koeretoej_side')

    soup = BeautifulSoup(response.content)

    try:
        return soup.find('input', attrs={'name': 'dmrFormToken'})['value']
    except (TypeError, KeyError):
        return None
{'fraction_non_alphanumeric': 0.10577568838146408, 'fraction_numerical': 0.0033579583613163196, 'mean_word_length': 3.225531914893617, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2454957', 'n_tokens_mistral': 985, 'n_tokens_neox': 948, 'n_words': 217}