-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
oai config #3
Merged
Merged
oai config #3
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: config oai server client
Signed-off-by: Peter Weber <Peter.Weber@rero.ch> Co-authored-by: Bertrand Zuchuat <Bertrand.Zuchuat@rero.ch>
- Loading branch information
commit df566a02fc78821b67a359eaad9ca10f9bf7d7ca
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# Copyright (C) 2018 RERO. | ||
# | ||
# RERO Ebooks is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
# | ||
# OAI-PMH connection settings | ||
|
||
VS: | ||
baseurl: https://mediatheque-valais.cantookstation.eu/oai.xml | ||
metadataprefix: marc21 | ||
comment: 'cantook' | ||
setspecs: '' | ||
NJ: | ||
baseurl: https://bm.ebibliomedia.ch/oai.xml | ||
metadataprefix: marc21 | ||
comment: 'cantook' | ||
setspecs: '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2018 RERO. | ||
# | ||
# RERO Ebooks is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""RERO DOC Invenio application.""" | ||
|
||
|
||
from invenio_oaiharvester.signals import oaiharvest_finished | ||
|
||
from . import config | ||
from .receivers import publish_harvested_records | ||
|
||
|
||
class ReroEBooks(object): | ||
"""ReroEBooks App extension.""" | ||
|
||
def __init__(self, app=None): | ||
"""Extension initialization.""" | ||
if app: | ||
self.init_app(app) | ||
self.register_signals(app) | ||
|
||
def init_app(self, app): | ||
"""Flask application initialization.""" | ||
self.init_config(app) | ||
app.extensions['reroebooks-app'] = self | ||
|
||
def init_config(self, app): | ||
"""Initialize configuration.""" | ||
for k in dir(config): | ||
if k.startswith('REROEBOOKS_APP_'): | ||
app.config.setdefault(k, getattr(config, k)) | ||
|
||
@staticmethod | ||
def register_signals(app): | ||
"""Register Zenodo Deposit signals.""" | ||
oaiharvest_finished.connect(publish_harvested_records, | ||
weak=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2018 RERO. | ||
# | ||
# RERO Ebooks is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""Signals connections for RERO ebooks.""" | ||
|
||
from dojson.contrib.marc21.utils import create_record | ||
|
||
from rero_ebooks.tasks import create_records | ||
|
||
from .dojson.marc21 import marc21 | ||
|
||
|
||
def publish_harvested_records(sender=None, records=[], *args, **kwargs): | ||
"""Create, index the harvested records.""" | ||
# name = kwargs['name'] | ||
converted_records = [] | ||
for record in records: | ||
rec = create_record(record.xml) | ||
rec = marc21.do(rec) | ||
converted_records.append(rec) | ||
verbose = kwargs.get('verbose', False) | ||
create_records(converted_records, verbose=verbose) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2018 RERO. | ||
# | ||
# RERO Ebooks is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""Celery tasks to create records.""" | ||
|
||
from __future__ import absolute_import, print_function | ||
|
||
import click | ||
from celery import shared_task | ||
from invenio_oaiharvester.api import list_records | ||
from invenio_oaiharvester.signals import oaiharvest_finished | ||
|
||
from .api import Ebook | ||
|
||
|
||
@shared_task(ignore_result=True) | ||
def create_records(records, verbose=False): | ||
"""Records creation and indexing.""" | ||
for record in records: | ||
rec, status = Ebook.create_or_update( | ||
record, | ||
# TODO vendor config | ||
vendor='cantook', | ||
dbcommit=True, | ||
reindex=True | ||
) | ||
if verbose: | ||
click.echo('record uuid: ' + str(rec.id) + ' | ' + status) | ||
# TODO bulk update and reindexing | ||
|
||
|
||
@shared_task(ignore_result=True) | ||
def harvest(source, verbose=False): | ||
"""Async source harvesting.""" | ||
records = None | ||
request, records = list_records( | ||
name=source | ||
) | ||
if records: | ||
oaiharvest_finished.send( | ||
request, | ||
records=records, | ||
name=source, | ||
verbose=verbose | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2018 RERO. | ||
# | ||
# RERO Ebooks is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""Utilities.""" | ||
|
||
|
||
from flask import current_app | ||
from invenio_db import db | ||
from invenio_oaiharvester.models import OAIHarvestConfig | ||
|
||
|
||
def add_oai_source(name, baseurl, metadataprefix='marc21', | ||
setspecs='', comment=''): | ||
"""Add OAIHarvestConfig.""" | ||
with current_app.app_context(): | ||
source = OAIHarvestConfig( | ||
name=name, | ||
baseurl=baseurl, | ||
metadataprefix=metadataprefix, | ||
setspecs=setspecs, | ||
comment=comment | ||
) | ||
source.save() | ||
db.session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyright?