forked from chinese-soup/zradlo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsilencio.py
executable file
·81 lines (63 loc) · 2.11 KB
/
silencio.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
#!/usr/bin/env python3
# coding=utf-8
import requests, sys, re, time, locale
from bs4 import BeautifulSoup
# locale.setlocale(locale.LC_ALL,'cs_CZ.UTF-8')
locale.setlocale(locale.LC_ALL,'')
def get_url():
return "http://www.silencio.cafe/kde-nas-najdete/"
#return "http://restauracehamburg.cz/homepage/poledni-menicka"
def get_name():
return "Silencio Café"
def get_file():
kantyna = requests.get("http://www.silencio.cafe/denni-nabidka/")
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):
today = time.strftime("%A")
#print(today)
items = []
published = False
date = "???"
date = today+" "+soup.find("div", { "class": "et_pb_text et_pb_module et_pb_bg_layout_dark et_pb_text_align_center et_pb_text_0" }).p.text.strip()
days = soup.find_all("div", { "class": "et_pb_toggle" })
#print(days)
for day in days:
dow = day.h5.text
if dow == today:
jidla = day.find_all("strong")
for jidlo in jidla:
items.append([jidlo.text, ""])
#print(soup)
#print(date)
return(date, items)
def result():
try:
file = get_file()
bs = prepare_bs(file)
#date = return_date(bs)
nazev = get_name()
url = get_url()
lokalita = "holesovice"
date, menu_list = return_menu(bs)
return(nazev, url, date, menu_list, lokalita)
except Exception as e:
print(e)
#return (get_name() + "- Chyba", "", str(e), [])
nazev = get_name()
url = get_url()
lokalita = "holesovice"
return (nazev, url, "Menu nenalezeno", [], lokalita)
if __name__ == "__main__":
file = get_file()
bs = prepare_bs(file)
#date = return_date(bs)
# date, menu_list = return_menu(bs)
# print(date, menu_list)
#debug_print(date, menu_list)