Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

recordcdsconfpaper.py 4.14 KB
Newer Older
1
""" store_tools.recordcdsconfpaper
2 3

"""
4 5
import re

6
from .base import T4, T6
7
from .cdsstore import CdsStore
8
from .confmixin import ConfMixin
9 10 11
from .recordcdspubli import RecordCdsPubli

REX_DATE8 = re.compile(r"(\d{4})(\d{2})(\d{2})")
12 13


14
class RecordCdsConfPaper(RecordCdsPubli, ConfMixin):
LE GAC Renaud's avatar
LE GAC Renaud committed
15 16
    """The record describing a conference talk or a proceeding.

17 18 19 20 21 22 23 24 25 26 27
    Attributes:
        conference (dict or None):
            the conference metadata:
                * addresses: [{cities: [], country: str, ...}, ...]
                * cnum: str
                * control_number: int
                * closing_date: str
                * opening_date: str
                * titles: [{value: str}, ...]
                * urls: [{value: str}, ...]
                * year
28

29
    """
LE GAC Renaud's avatar
LE GAC Renaud committed
30

31
    def __init__(self, recjson):
32

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
        super().__init__(recjson)

        self.conference = None
        self._process_conference_data()

    def _process_conference_data(self):
        """Append the conference data to the record.

        """
        logger = self.logger
        logger.debug(f"{T4}process conference data")

        if "aleph_linking_page" not in self:
            logger.debug(f"{T6}no field 'aleph_linking_page'")
            return

        dct = self.get("aleph_linking_page", {})
        conf_id = dct.get("sysno", None)
        conf_key = dct.get("up_link", None)

        if conf_id is None and conf_key is None:
            logger.debug(f"{T6}no conference id and key")
            return

        # ........................................................................
        #
        # Get conference data first id and then by key
        #
        store = CdsStore("cds.cern.ch")

        if conf_id is not None:
            logger.debug(f"{T6}search by conference by id {conf_id}")
            recjson = store.get_record(conf_id)

67
            if recjson["recid"] != int(conf_id):
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
                logger.debug(f"{T6}failed to retrieve conference by id")

            if recjson.get("meeting_name", None) is None:
                logger.debug(f"{T6}no field 'meeting_name'")
                return

        elif conf_key is not None:
            logger.debug(f"{T6}search by conference by key {conf_key}")
            ids = store.get_ids(p=conf_key)

            mtch = False
            for cid in ids:
                recjson = store.get_record(cid)

                for elt in recjson.get("meeting_name", []):
                    ck = elt.get("coference_code", "")
                    if ck == conf_key:
                        mtch = True
                        break

                if mtch is True:
                    break

            if mtch is False:
                logger.debug(f"{T6}failed to retrieve conference by key")
                return

        # ........................................................................
        #
        # Decode conference data
        # Convert structure to the one provides by the new inspirehep.net
        #
        data = None
        for elt in recjson["meeting_name"]:
            if "year" in elt:
                data = elt
                break

        if data is None:
            logger.debug(f"{T6}conference data not found")
            return

        city, country = data.get("location", ",").split(",")
111
        url = recjson.get("url", {}).get("url", None)
112 113 114 115 116 117 118

        dct = {
            "addresses": [{
                "cities": [city.strip()],
                "country": country.strip()}],
            "cnum": data.get("coference_code"),
            "closing_date": data.get("closing_date", None),
119
            "control_number": recjson["recid"],
120
            "opening_date": data.get("opening_date", None),
121 122
            "titles": [{"title": data.get("meeting", None)}],
            "urls": (None if url is None else [{"value": url}]),
123 124 125 126 127 128 129 130 131 132 133 134
            "year": data.get("year", None)}

        # date format issue YYYYMMDD to YYYY-MM-DD
        for k in ("closing_date", "opening_date"):
            mtch = REX_DATE8.match(dct[k])
            if mtch:
                dct[k] = "-".join(mtch.groups())

        # ........................................................................
        #
        # Append conference data
        self.conference = dct