forked from chinese-soup/zradlo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvyskocilka.py
executable file
·78 lines (61 loc) · 1.93 KB
/
vyskocilka.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
#!/usr/bin/env python3
# coding=utf-8
import requests, sys, re
# from datetime import datetime
from bs4 import BeautifulSoup
def get_url():
return "http://www.vyskocilka-restaurace.cz/denni-menu/"
def get_name():
return "Vyskočilka"
def get_file():
kantyna = requests.get(get_url())
kantyna.encoding = 'WINDOWS-1250'
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("div", { "class": "text" })
#print(a)
date = a.find("h3").find("strong").text.strip()
# print(date)
zradla = a.find_all("th") + a.find_all("td")
#print (zradla)
items = []
for item in zradla:
# print(item)
if item.text:
text = item.text
#print(text)
arr = []
match = re.match("([\w\d\sěščřžýáíéúůóÓĚŠČŘŽÝÁÍÉÚŮöäëÄÖËťŤ\"\(\)\,\-]+)[\s]+([0-9]{2,3}[\s]*,-)", text)
if match is not None:
arr = [match.group(1).strip(), match.group(2).strip()]
else:
continue
items.append(arr)
return(items, date)
def result():
try:
file = get_file()
bs = prepare_bs(file)
nazev = get_name()
url = get_url()
lokalita = "brumlovka"
menu_list, date = return_menu(bs)
return (nazev, url, date, menu_list, lokalita)
except Exception as e:
print(e)
nazev = get_name()
url = get_url()
lokalita = "brumlovka"
return (nazev, url, "Menu nenalezeno", [], lokalita)
if __name__ == "__main__":
file = get_file()
bs = prepare_bs(file)
menu_list, date = return_menu(bs)
print (date, menu_list)