""" harvest_tools.talks """ import traceback <<<<<<< HEAD from .automaton import Automaton from .base import MSG_CRASH, MSG_LOAD from .checkandfix import CheckException from plugin_dbui import UNDEF_ID ======= from automaton import Automaton from base import MSG_CRASH, MSG_LOAD from checkandfix import CheckException from plugin_dbui import get_id, UNDEF_ID >>>>>>> Modify the logic to deal with synonyms. class Talks(Automaton): """Automaton for conference talks. """ def check_record(self, record): """Check the content of the talk in order to fix non conformities. Args: record (RecordConf): record describing a conference. Returns: bool: ``False`` when a non conformity is found and can not be corrected. """ if not Automaton.check_record(self, record): return False if self.dbg: print("check talk record") try: self.check.is_conference(record) self.check.country(record) self.check.conference_date(record) self.check.submitted(record) self.check.format_authors(record, fmt="F. Last") self.check.get_my_authors(record, sort=True) except CheckException as e: self.logs[-1].reject(e, record=record) return False except Exception as e: self.logs[-1].reject(MSG_CRASH % e, record=record, translate=False) print(traceback.format_exc()) return False return True def insert_record(self, record): """Insert a conference talk in the database. Args: record (RecordConf): record describing a conference. Returns: int: one when the record is inserted / updated in the database zero otherwise. """ db = self.db # alias oai_url = record.oai_url() year = record.conference_year() # alias for the conference information conference_dates = record.conference_dates() conference_title = record.conference_title() first_author = record.first_author() id_country = get_id(db.countries, country=record.conference_country()) submitted = record.submitted() title = record.title() # get the collaboration identifier id_collaboration = \ get_id(db.collaborations, collaboration=record.collaboration()) # get an already published talk fields = dict(conference_title=conference_title, first_author=first_author, title=title) rec_id, status = self.get_record_by_fields(oai_url, year, **fields) if rec_id: return status # eventually insert a new talk ret = 1 if not self.dry_run: fields = dict(authors=record.authors(), authors_institute=record.my_authors, conference_dates=conference_dates, conference_speaker=first_author, conference_title=conference_title, conference_town=record.conference_town(), conference_url=record.conference_url(), first_author=first_author, id_categories=self.id_category, id_collaborations=id_collaboration, id_countries=id_country, id_projects=self.id_project, id_status=UNDEF_ID, id_teams=self.id_team, origin=oai_url, submitted=submitted, title=title, year=year) ret = self._insert_in_db(log_year=year, **fields) if ret == 1: self.logs[-1].load(MSG_LOAD, year) return 1 return 0