-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharxiv_completeness.py
63 lines (49 loc) · 1.82 KB
/
arxiv_completeness.py
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
from datetime import date, datetime, timedelta
import logging
from errbot import BotPlugin, arg_botcmd
from errcron import CrontabMixin
from lib import arxiv_completness_check_script
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
def get_default_from_date():
today = date.today()
if today.weekday() == 0:
return today - timedelta(days=3)
return today - timedelta(days=1)
class ArxivCompleteness(CrontabMixin, BotPlugin):
"""
Arxiv Completeness Errbot Plugin
"""
CRONTAB = ["0 10 * * 1-5 .daily_check"]
TIMEZONE = "Europe/Zurich"
@arg_botcmd("--from-date", dest="from_date", type=str, default=None)
@arg_botcmd("--to-date", dest="to_date", type=str, default=None)
def arxiv(self, msg, from_date, to_date):
"""
Command that retrieves information regarding the harvesting between two dates
"""
if from_date is not None:
from_date = datetime.strptime(from_date, "%Y-%m-%d").date()
else:
from_date = get_default_from_date()
if to_date is not None:
to_date = datetime.strptime(to_date, "%Y-%m-%d").date()
else:
to_date = date.today()
yield "Arxiv Completeness Check may take some time, please be patient"
yield arxiv_completness_check_script.completeness_check(from_date, to_date)
def daily_check(self, polled_time):
client = self._bot.client
logger.info("Daily Check Start")
message = arxiv_completness_check_script.completeness_check(
get_default_from_date(), date.today()
)
logger.info(message)
client.send_message(
{
"type": "stream",
"to": "inspire",
"topic": "harvest",
"content": message,
}
)