S
S
Sergey Protasov2020-06-05 10:12:14
Django
Sergey Protasov, 2020-06-05 10:12:14

How to detect Russian holidays and weekends in python?

How to detect Russian holidays and weekends in python? Are there any ready-made solutions?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Kuts, 2020-06-05
@protasovse

Parse some resource with a production calendar, and write a check method, something like this:

YEAR_HOLIDAYS = 'HOLIDAYS:{year}' 

   ...
    @classmethod
    def is_work_day(cls, date):
        if date.weekday() in [5,6]:
            return False
        holidays = cache.get(YEAR_HOLIDAYS.format(year=date.year))
        if not holidays:
            holidays = cls.objects.filter(year=date.year).values_list('date', flat=True)
            cache.set(YEAR_HOLIDAYS.format(year=date.year), holidays)
        if date in holidays:
            return False
        return True

Add the logic of transferring working days here - and in production..

S
Sergey Gornostaev, 2020-06-05
@sergey-gornostaev

How to find out the date which will be in n days, where n is excluding weekends, after a certain date in python?

O
o5a, 2020-06-05
@o5a

It is worth searching for the words "production calendar" and, if possible, "API", there are different options
. For example, there are
https://isdayoff.ru/extapi/
Sample request
https://isdayoff.ru/api/getdata?year=2020&month =06...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question