forked from openlibhums/doaj_transporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.py
More file actions
42 lines (32 loc) · 1.19 KB
/
events.py
File metadata and controls
42 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
Event handlers that can be installed with Janeway's event system
"""
import traceback as tb
from events import logic as events_logic
from utils.logger import get_logger
from utils.setting_handler import get_setting
from plugins.doaj_transporter import logic
logger = get_logger(__name__)
def push_on_publication(article, *args, **kwargs):
journal = article.journal
setting = get_setting("plugin", "doaj_api_token", journal=journal)
if not setting or not setting.value:
# Check press default
setting = get_setting("plugin", "doaj_api_token", journal=None)
if not setting or not setting.value:
logger.info("Journal has no DOAJ Token, ignoring...")
return
enabled = get_setting("plugin", "doaj_publish_push", journal=journal).value
if enabled:
try:
logic.push_article_to_doaj(article)
except Exception as e:
logger.error("Failed to push article to DOAJ:")
tb.print_exc()
else:
logger.info("DOAJ push disabled for journal, ignoring...")
def register_for_events():
events_logic.Events.register_for_event(
events_logic.ON_ARTICLE_PUBLISHED,
push_on_publication,
)