Commit 42906b79 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the script

parent eff33421
# -*- coding: utf-8 -*-
""" NAME
Copy ACTI to COM for the CPPM database.
Up to the end of 2014 a talk to a conference (COM) is transformed
into a proceeding (ACTI) when the later is published.
In 2015, the policy changes, COM and ACTI are kept as separated
This script implement the new policy for the publications registered
before 2015. It mainly copy the ACTI into COM for the year from
2009 up to 2014.
-h, --help
Display the help and exit.
> cd ...track_publications/scripts
> ./run -S test_publications script
> ./run -S track_publications script
R. Le Gac -- Jan 2016
import re
REG_ORIGIN = re.compile("https?://([a-z\.]+)/record/(\d+)")
if __name__ == "__main__":
import sys
from argparse import ArgumentParser, FileType
from invenio_tools import load_record, OAI_URL
from plugin_dbui import CALLBACK_ERRORS, get_id
# command line options
parser = ArgumentParser()
args = parser.parse_args()
# get the ACTI / COM identifier
id_acti = get_id(db.categories, code="ACTI")
id_com = get_id(db.categories, code="COM")
# build the query
query = db.publications.id_categories == id_acti
query &= db.publications.year >= 2009
query &= db.publications.year <= 2014
# scan the publications table
for row in db(query).select():
data = row.as_dict()
# skip if the the speaker is not from CPPM
if data["conference_speaker"] not in data["authors_institute"]:
# remove publisher information
data["id_publishers"] = 1
data["pages"] = ""
data["volume"] = ""
data["submitted"] = ""
data["publication_url"] = ""
data["preprint"] = ""
# the year is the one of the conference
conference_dates = data["conference_dates"]
if conference_dates:
data["year"] = int(data["conference_dates"][-4:])
print "No conferences dates", data["id"]
# change the category and the status
data["id_categories"] = id_com
data["id_status"] = 1
# change the origin
val = data["origin"]
if val:
origin = val.split(',')[0].strip()
match = REG_ORIGIN.match(origin)
host, rec_id =,
proceeding = load_record(host, rec_id)
talk_id = proceeding.reference_conference_talk()
data["origin"] = (OAI_URL % (host, talk_id) if talk_id else "")
# insert the new record in the database
id_rec = data["id"],
del data["id"]
id_new = db.publications.insert(**data)
print "Copy", id_rec, "→",
if id_new:
print id_new
elif CALLBACK_ERRORS in db.publications:
print " ".join(db.publications._callback_errors)
print "???"
# commit change
rep = raw_input("Commit change in the database? [y/N]:")
if rep == 'y':
print "The database is modified."
# close
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