Commit 28aae2f0 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Merge branch '66-no-conference-date' into 'master'

66 no conference date

* Fix `RecordConf.conference_dates` for record from inspirehep.net.
* Modify the logic to check and validate conference dates. It now depends on the record host.
* Close #66 

See merge request !66
parents f08371a2 1d5db947
...@@ -216,7 +216,7 @@ def edit_insert(): ...@@ -216,7 +216,7 @@ def edit_insert():
try: try:
check.country(record) check.country(record)
check.conference_date(record) check.conference_date(record, selector.host)
except CheckException: except CheckException:
pass pass
......
...@@ -395,11 +395,13 @@ class CheckAndFix(object): ...@@ -395,11 +395,13 @@ class CheckAndFix(object):
except ToolException as e: except ToolException as e:
raise CheckException(*e.args) raise CheckException(*e.args)
def conference_date(self, record): def conference_date(self, record, host):
"""Check conference date. """Check conference date.
Args: Args:
record (RecordConf): record describing a talk or a proceeding. record (RecordConf): record describing a talk or a proceeding.
host (str): possible values ares ``cds.cern.ch``
or ``inspirehep.net``
Raises: Raises:
CheckException: when dates are not found or not well formed. CheckException: when dates are not found or not well formed.
...@@ -409,11 +411,20 @@ class CheckAndFix(object): ...@@ -409,11 +411,20 @@ class CheckAndFix(object):
if not isinstance(record, RecordConf): if not isinstance(record, RecordConf):
return return
# check and fix conference date # inspirehep.net
if host == "inspirehep.net":
value = record.conference_dates()
if len(value) == 0:
raise CheckException(MSG_NO_CONF_DATE)
return
# cds.cern.ch
if not (u"111" in record and "d" in record[u"111"]): if not (u"111" in record and "d" in record[u"111"]):
raise CheckException(MSG_NO_CONF_DATE) raise CheckException(MSG_NO_CONF_DATE)
value = record[u"111"]["d"] value = record[u"111"]["d"]
m = REG_CONF_DATES.match(value) m = REG_CONF_DATES.match(value)
if not m: if not m:
......
...@@ -35,7 +35,7 @@ class Proceedings(Automaton): ...@@ -35,7 +35,7 @@ class Proceedings(Automaton):
try: try:
self.check.is_conference(record) self.check.is_conference(record)
self.check.country(record) self.check.country(record)
self.check.conference_date(record) self.check.conference_date(record, self.harvester.host)
self.check.clean_erratum(record) self.check.clean_erratum(record)
self.check.submitted(record) self.check.submitted(record)
......
...@@ -35,7 +35,7 @@ class Talks(Automaton): ...@@ -35,7 +35,7 @@ class Talks(Automaton):
try: try:
self.check.is_conference(record) self.check.is_conference(record)
self.check.country(record) self.check.country(record)
self.check.conference_date(record) self.check.conference_date(record, self.harvester.host)
self.check.submitted(record) self.check.submitted(record)
self.check.year(record) self.check.year(record)
......
...@@ -6,7 +6,6 @@ import pprint ...@@ -6,7 +6,6 @@ import pprint
from base import OAI, OAI_URL, REG_OAI from base import OAI, OAI_URL, REG_OAI
from __builtin__ import isinstance
class Record(dict): class Record(dict):
......
...@@ -2,11 +2,18 @@ ...@@ -2,11 +2,18 @@
""" invenio_tools.recordconf """ invenio_tools.recordconf
""" """
import re
from base import REG_YEAR from base import REG_YEAR
from datetime import datetime
from plugin_dbui import CLEAN_SPACES from plugin_dbui import CLEAN_SPACES
from recordpubli import RecordPubli from recordpubli import RecordPubli
REG_DATE = re.compile(r"(\d{4}-\d{2}-\d{2})")
class RecordConf(RecordPubli): class RecordConf(RecordPubli):
"""The MARC record describing a conference talk or a proceeding. """The MARC record describing a conference talk or a proceeding.
The relation between methods and MARC fields are the following:: The relation between methods and MARC fields are the following::
...@@ -14,8 +21,8 @@ class RecordConf(RecordPubli): ...@@ -14,8 +21,8 @@ class RecordConf(RecordPubli):
+-----------------------+---------+----------+ +-----------------------+---------+----------+
| | CDS | INSPIREP | | | CDS | INSPIREP |
+-----------------------+---------+----------+ +-----------------------+---------+----------+
| conference date | 111 d | | | conference date | 111 d | None |
| conference end | 111 z | None | | conference end | 111 z | 111 y |
| conference key | 111 g | | | conference key | 111 g | |
| conference location | 111 c | | | conference location | 111 c | |
| conference title | 111 a | | | conference title | 111 a | |
...@@ -38,7 +45,27 @@ class RecordConf(RecordPubli): ...@@ -38,7 +45,27 @@ class RecordConf(RecordPubli):
standardise. standardise.
""" """
return self._get(u"111", "d") if self.host().startswith("inspirehep"):
start = self._get(u"111", "x")
end = self._get(u"111", "y")
if not (REG_DATE.match(start) and REG_DATE.match(end)):
return u''
ds = datetime.strptime(start, "%Y-%m-%d")
de = datetime.strptime(end, "%Y-%m-%d")
if ds.month == de.month:
value = "%i-%i %s" % (ds.day, de.day, ds.strftime("%b %Y"))
else:
tpl = (ds.strftime("%d %b"), de.strftime("%d %b %Y"))
value = "%s - %s" % tpl
else:
value = self._get(u"111", "d")
return value
def conference_country(self): def conference_country(self):
"""The country where the conference took place. """The country where the conference took place.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment