Exemplo n.º 1
0
    def get_resurrection_day(self):
        """Get date of the Orthodox Resurrection day."""

        result = ''
        if self.__calendar == 'julian':
            day, month, year = convert_julian_day_to_julian_am(
                self.__julian_date_easter)
            result = [u'%d %s %d года %s' % (
                day, MONTH_JULIAN_WORD[month], year, self.__style)]
        elif self.__calendar == 'gregorian':
            day, month, year = convert_julian_to_gregorian(
                *get_pascha(self.__year))
            result = [u'%d %s по %s' % (day, MONTH_WORD[month], self.__style)]

        return dict(
            headline=u'Пасха',
            result=result
        )
Exemplo n.º 2
0
 def __set_date(self, day, month, year=datetime.today().year):
     if self.__calendar == 'gregorian':
         day, month, year = convert_julian_to_gregorian(day, month, year)
     _date = u'%s %s' % (unicode(day), MONTH_WORD[month])
     return _date
Exemplo n.º 3
0
 def __get_absolute_date(self, date):
     if self.__calendar == 'gregorian':
         date = convert_julian_to_gregorian(*date)
     return date
Exemplo n.º 4
0
def search_feasts(search_string):
    """
    Search saints and feasts in year menology.
    :param search_string: search input string (e.g. saint or feast name).
    :return list, witch contains gregorian & julian dates and search result.
    """
    if len(search_string) < 3:
        return dict(count=0, result=[])

    # TODO: Fix endings in the words: Андрей, Андриан
    endings = re.compile(
        ur"(ый|ой|ая|ое|ые|ому|а|ем|о|ов|у|е|й|" ur"ого|ал|ему|и|ство|ых|ох|ия|ий|ь|я|он|ют|ат|ин|ея)$", re.U
    )

    search_string_clean = re.sub(endings, u"", search_string)
    pattern = re.compile(ur"(\b%s\w+\b)" % search_string_clean, re.I | re.U)

    if len(search_string) <= 5:
        endings = re.compile(ur"(а|ы|у|и|я)$", re.U)

        search_string_clean = re.sub(endings, u"", search_string)
        pattern = re.compile(ur"(\b%s[а-я]{0,2}\b)" % search_string_clean, re.I | re.U)

    date = datetime.date.today()
    year = convert_gregorian_to_julian(date.day, date.month, date.year)[2]
    year_menology = menology
    cal_out = []

    # List of weekday names.
    for month in range(1, 13):
        days_in_month = calendar.monthrange(year, month)[1]
        for day in range(1, days_in_month + 1):
            cal = AncientCalendar(day, month, year, calendar="julian")
            weekdayname = cal.get_daily_feast()
            cal_out.extend([[list((day, month, year)), weekdayname]])

    # Construct year menology with movable feasts.
    for item in cal_out:
        year_menology[item[0][1]][item[0][0]]["weekday"] = item[1]

    d = year_menology
    out = []

    # Search string in menology.
    for _month, value in d.iteritems():
        for _day, value1 in d[_month].iteritems():
            for key2, content in d[_month][_day].iteritems():

                if re.search(pattern, unicode(content)):
                    _date = (_day, _month, year)
                    out.extend(
                        [
                            [
                                list(convert_julian_day_to_julian_am(convert_julian_to_julian_day(*_date))),
                                list(convert_julian_to_gregorian(*_date)),
                                clean_string(content),
                            ]
                        ]
                    )

    # Highliting search_string.
    start_str = u"{highlight_start}"
    end_str = u"{highlight_end}"

    pattern_highlite = re.compile(ur"(\b%s\w*\b)" % search_string_clean, re.I | re.U)

    tr = lambda m: start_str + m.group() + end_str

    result = [[t[0], t[1], pattern_highlite.sub(tr, t[2])] for t in out]
    # Count of serach results.
    count = len([re.findall(pattern, item[2]) for item in out])

    return dict(count=count, result=result)