This repository has been archived by the owner on Dec 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
kantyna.py
executable file
·77 lines (62 loc) · 2.01 KB
/
kantyna.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
# coding=utf-8
import requests, sys, re
from bs4 import BeautifulSoup
def get_url():
return "http://www.manihi.cz/zavodni-stravovani-kantyna/kantyna-rosmarin-business-center/denni-menu"
def get_name():
return "Kantýna"
def get_file():
kantyna = requests.get(get_url())
return kantyna
def prepare_bs(kantyna):
if kantyna is not None and kantyna.status_code == 200:
html = kantyna.text
soup = BeautifulSoup(html, 'html.parser')
return soup
else:
return "Error"
def return_menu(soup):
a = soup.find_all("div", { "class": "widget widgetWysiwyg clearfix" })[0].find_all("p")
print(a)
items = []
for item in a:
if "CHCETE" not in item.text and "čipové" not in item.text and "2017" not in item.text:
print(item.text)
#split = text.split("–")
text = item.text
arr = []
match = re.match("(.*?)([0-9]{2,3}\s+Kč)", text)
if match is not None:
arr = [match.group(1).strip(), match.group(2).strip()]
else:
continue
items.append(arr)
return items
def return_date(soup):
b = soup.find_all("div", { "class": "widget widgetWysiwyg clearfix" })
b = b[0].find_all("p")[0].text
b = b.replace("DENNÍ NABÍDKA ", "")
return(b)
def debug_print(date, menu):
print(date)
def result():
try:
file = get_file()
bs = prepare_bs(file)
nazev = get_name()
url = get_url()
date = return_date(bs)
menu_list = return_menu(bs)
print(date, menu_list)
return(nazev, url, date, menu_list)
except Exception as exp:
print(exp)
return(get_name() + "- Chyba", "", "", [str(exp)])
if __name__ == "__main__":
file = get_file()
bs = prepare_bs(file)
date = return_date(bs)
menu_list = return_menu(bs)
lol()
#debug_print(date, menu_list)