forked from chinese-soup/zradlo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextolinn.py
executable file
·96 lines (76 loc) · 2.54 KB
/
extolinn.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
91
92
93
94
95
96
#!/usr/bin/env python3
# coding=utf-8
import requests, sys, re, time, locale
from bs4 import BeautifulSoup
locale.setlocale(locale.LC_ALL,'')
def get_url():
return "http://extolinn.cz/main/daily_menu"
def get_name():
return "Extol Inn"
def get_file():
user_agent = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'cs,sk;q=0.8,en-US;q=0.5,en;q=0.3',
'User-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0',
}
session = requests.Session()
r = session.get("http://extolinn.cz/main/set_lang/czech", headers = user_agent)
#print(r.cookies)
kantyna = session.get(get_url(), headers = user_agent)
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_all("div", { "class": "container" })[1].find_all("div" )
#print (jidlo_obsah)
jidlo_cena = []
items = []
today = time.strftime("%A - %d.%m.%Y")
published = False
# print(today)
date = "???"
for i in a:
if published:
jidlo_obsah = i.find_all("tr")
for line in jidlo_obsah:
zradlo = line.find_all("td")
# print (zradlo)
nazev = zradlo[2].text
cena = zradlo[3].text
# print(cena)
# print(nazev)
arr = [nazev, cena]
items.append(arr)
break
if i.text.strip() == today:
published = True
date = today
return(items, date)
def result():
try:
file = get_file()
bs = prepare_bs(file)
#date = return_date(bs)
nazev = get_name()
url = get_url()
lokalita = "holesovice"
menu_list, date = 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()
lokalita = "holesovice"
url = get_url()
return (nazev, url, "Menu nenalezeno", [], lokalita)
if __name__ == "__main__":
file = get_file()
bs = prepare_bs(file)
#date = return_date(bs)
menu_list, date = return_menu(bs)
print(date, menu_list)