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
/
pinta.py
executable file
·90 lines (68 loc) · 2.27 KB
/
pinta.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
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
# coding=utf-8
import requests, sys, re
from bs4 import BeautifulSoup
def get_url():
return "http://www.pinta-restaurace.cz/denni_menu.php"
def get_name():
return "Pinta"
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.content
soup = BeautifulSoup(html.decode('utf-8', 'ignore'), 'html.parser')
return soup
else:
return None
def return_menu(soup):
a = soup.find("div", { "class": "dailyMenu" })
#b = a.findNext("dm-day").text
#c = b.findNext("p").text
#d = re.split(" Kč", c)
#date = soup.find("div", { "style": "background: rgba(34, 15, 15, .30); font-size: 20px; border-bottom: 1px solid #b7a56d;" }).text
date = ""
try:
date = ""
date = soup.find_all("td", { "style":re.compile(r".*background: rgba(34, 15, 15, .30).*") } )[0].text
except:
date = ""
jidlo_obsah = soup.find_all("td", { "style":re.compile(r".*width: 100%.*") } )
jidlo_cena = []
arr = []
for i in range(0, len(jidlo_obsah)):
a = jidlo_obsah[i].text
try:
b = jidlo_obsah[i].findNext("td").text
if a is not "":
print(a)
print(b)
arr.append([a, b])
except Exception as ex:
print("Err" + str(ex))
# jidlo_cena.append(jidlo_obsah[i].findNext("td").text)
# arr.append([jidlo_obsah[i].text, jidlo_cena[i].text])
items = arr
print("ITEMS {0}".format(items))
print("DATE", date)
return(items, date)
def result():
try:
file = get_file()
bs = prepare_bs(file)
#date = return_date(bs)
nazev = get_name()
url = get_url()
menu_list, date = return_menu(bs)
return(nazev, url, date, menu_list)
except Exception as e:
print(e)
return (get_name() + "- Chyba", "", str(e), [])
if __name__ == "__main__":
file = get_file()
bs = prepare_bs(file)
#date = return_date(bs)
menu_list = return_menu(bs)
print(menu_list)
#debug_print(date, menu_list)