-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
102 lines (82 loc) · 2.79 KB
/
tasks.py
File metadata and controls
102 lines (82 loc) · 2.79 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Create your tasks here
from celery import shared_task
from jdhapi.models import Abstract
from django.core.mail import send_mail
from celery.utils.log import get_task_logger
from .models import Article
from jdhapi.utils.articles import (
get_notebook_stats,
get_notebook_specifics_tags,
generate_tags,
generate_narrative_tags,
get_notebook_references_fulltext,
)
logger = get_task_logger(__name__)
@shared_task
def add(x, y):
return x + y
@shared_task
def mul(x, y):
return x * y
@shared_task
def xsum(numbers):
return sum(numbers)
@shared_task
def count_abstracts():
return Abstract.objects.count()
@shared_task
def send_confirmation():
try:
send_mail(
"test subject",
"test body",
"jdh.admin@uni.lu",
["elisabeth.guerard@uni.lu"],
fail_silently=False,
)
except Exception as e: # catch *all* exceptions
logger.error(f"send_confirmation exception:{e}")
@shared_task
def save_article_fingerprint(article_id):
logger.info(f"save_article_fingerprint article_id:{article_id}")
try:
article = Article.objects.get(pk=article_id)
except Article.DoesNotExist:
logger.error(f"save_article_fingerprint article_id:{article_id} not found")
fingerprint = get_notebook_stats(raw_url=article.notebook_ipython_url)
article.fingerprint = fingerprint
article.save()
@shared_task
def save_article_specific_content(article_id):
logger.info(f"save_article_specific_content:{article_id}")
try:
article = Article.objects.get(pk=article_id)
except Article.DoesNotExist:
logger.error(f"save_article_specific_content:{article_id} not found")
data = get_notebook_specifics_tags(article, raw_url=article.notebook_ipython_url)
article.data = data
article.save()
@shared_task
def save_libraries(article_id):
logger.info(f"save_article_libraries:{article_id}")
try:
article = Article.objects.get(pk=article_id)
except Article.DoesNotExist:
logger.error(f"save_article_citation:{article_id} not found")
feedback_tool = generate_tags(article=article)
feedback_narrative = generate_narrative_tags(article=article)
logger.info(feedback_tool)
logger.info(feedback_narrative)
@shared_task
def save_references(article_id):
logger.info(f"save_article_references:{article_id}")
try:
article = Article.objects.get(pk=article_id)
except Article.DoesNotExist:
logger.error(f"save_article_references:{article_id} not found")
logger.info("inside save_article_references")
references, bibliography, refs = get_notebook_references_fulltext(
article.abstract.pid, raw_url=article.notebook_ipython_url
)
# logger.info(f'References {references}')
logger.info(f"ok finish")