File size: 1,082 Bytes
73ee427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from requests import get
import re

def getHolidays(request):
    try:
        site = get("https://calend.online/holiday/").text
        site = site.partition('<ul class="holidays-list">')[2].partition('</ul>')[0]
        
        patterns = [
            r'<a\b[^>]*>',
            r'</a\b[^>]*>',
            r'<div\b[^>]*>',
            r'</div\b[^>]*>',
            r'<span\b[^>]*>',
            r'</span\b[^>]*>',
            r'<img\b[^>]*>',
            r'<meta\b[^>]*>',
            r'<li\b[^>]*>',
            r'</li\b[^>]*>',
            r'<small\b[^>]*>',
            r'</small\b[^>]*>',
            r'\b\d+\s+(?:лет|года)\b'
        ]
        
        for pattern in patterns: site = re.sub(pattern, '', site)
        while "  " in site: site = site.replace("  ", "")
        things = list(set(site.split("\n")))
        things.pop(0)
        return {"status": "pass", "details": {"code": 200, "result": '\n'.join(things)}}
    except Exception as e:
        print(e)
        return {"status": "error", "details": {"error_code": 500, "error_details": str(e)}}, 500