<commit_before>import logging
from datetime import datetime
from typing import Optional, Callable, Any, Sequence, Dict

from waitlist.storage.database import APICacheCorporationInfo
from waitlist.utility.outgate.exceptions import ESIException, check_esi_response
from waitlist.utility.swagger.eve import ESIResponse
from waitlist.utility.swagger.eve.corporation import CorporationEndpoint, CorporationInfo
from waitlist import db

logger = logging.getLogger(__name__)


def set_from_corp_info(self: APICacheCorporationInfo, info: CorporationInfo, corp_id: int):
    self.id = corp_id
    self.name = info.get_corporation_name()
    self.allianceID = info.get_alliance_id()
    self.ceoID = info.get_ceo_id()
    self.description = info.get_corporation_description()
    self.creatorID = info.get_creator_id()
    self.memberCount = info.get_member_count()
    self.taxRate = info.get_tax_rate()
    self.ticker = info.get_ticker()
    self.url = info.get_url()
    self.creationDate = info.get_creation_date()
    self.expire = info.expires()


def get_corp_info(corp_id: int, *args) -> APICacheCorporationInfo:
    corp_cache: APICacheCorporationInfo = db.session.query(APICacheCorporationInfo) \
        .filter(APICacheCorporationInfo.id == corp_id).first()

    if corp_cache is None:
        corp_cache = APICacheCorporationInfo()
        corp_ep = CorporationEndpoint()
        corp_info: CorporationInfo = check_esi_response(corp_ep.get_corporation_info(corp_id), get_corp_info, args)

        set_from_corp_info(corp_cache, corp_info, corp_id)
        db.session.add(corp_cache)
        db.session.commit()
    elif corp_cache.characterName is None:
        corp_ep = CorporationEndpoint()
        corp_info: CorporationInfo = check_esi_response(corp_ep.get_corporation_info(corp_id), get_corp_info, args)
        set_from_corp_info(corp_cache, corp_info, corp_id)
        db.session.commit()
    else:
        now = datetime.now()
        if corp_cache.expire is None or corp_cache.expire < now:
            # expired, update it
            corp_ep = CorporationEndpoint()
            try:
                corp_info: CorporationInfo = check_esi_response(corp_ep.get_corporation_info(corp_id), get_corp_info, args)
            except ESIException:
                return corp_cache
            set_from_corp_info(corp_cache, corp_info, corp_id)
            db.session.commit()

    return corp_cache<commit_msg>fixed exception in getting corporation info, because of trying to access wrong attribute for name of corp in APICacheInfo<commit_after>import logging
from datetime import datetime
from typing import Optional, Callable, Any, Sequence, Dict

from waitlist.storage.database import APICacheCorporationInfo
from waitlist.utility.outgate.exceptions import ESIException, check_esi_response
from waitlist.utility.swagger.eve import ESIResponse
from waitlist.utility.swagger.eve.corporation import CorporationEndpoint, CorporationInfo
from waitlist import db

logger = logging.getLogger(__name__)


def set_from_corp_info(self: APICacheCorporationInfo, info: CorporationInfo, corp_id: int):
    self.id = corp_id
    self.name = info.get_corporation_name()
    self.allianceID = info.get_alliance_id()
    self.ceoID = info.get_ceo_id()
    self.description = info.get_corporation_description()
    self.creatorID = info.get_creator_id()
    self.memberCount = info.get_member_count()
    self.taxRate = info.get_tax_rate()
    self.ticker = info.get_ticker()
    self.url = info.get_url()
    self.creationDate = info.get_creation_date()
    self.expire = info.expires()


def get_corp_info(corp_id: int, *args) -> APICacheCorporationInfo:
    corp_cache: APICacheCorporationInfo = db.session.query(APICacheCorporationInfo) \
        .filter(APICacheCorporationInfo.id == corp_id).first()

    if corp_cache is None:
        corp_cache = APICacheCorporationInfo()
        corp_ep = CorporationEndpoint()
        corp_info: CorporationInfo = check_esi_response(corp_ep.get_corporation_info(corp_id), get_corp_info, args)

        set_from_corp_info(corp_cache, corp_info, corp_id)
        db.session.add(corp_cache)
        db.session.commit()
    elif corp_cache.name is None:
        corp_ep = CorporationEndpoint()
        corp_info: CorporationInfo = check_esi_response(corp_ep.get_corporation_info(corp_id), get_corp_info, args)
        set_from_corp_info(corp_cache, corp_info, corp_id)
        db.session.commit()
    else:
        now = datetime.now()
        if corp_cache.expire is None or corp_cache.expire < now:
            # expired, update it
            corp_ep = CorporationEndpoint()
            try:
                corp_info: CorporationInfo = check_esi_response(corp_ep.get_corporation_info(corp_id), get_corp_info, args)
            except ESIException:
                return corp_cache
            set_from_corp_info(corp_cache, corp_info, corp_id)
            db.session.commit()

    return corp_cache
{'fraction_non_alphanumeric': 0.08000810208628722, 'fraction_numerical': 0.0, 'mean_word_length': 3.7344199424736337, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6531199', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1515, 'n_words': 303}