forked from chinese-soup/zradlo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlunchbox-delta.py
executable file
·81 lines (65 loc) · 1.91 KB
/
lunchbox-delta.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, os, re, tempfile, time, locale
from bs4 import BeautifulSoup
locale.setlocale(locale.LC_ALL,'')
def get_url():
return "https://goodlunch.cz/kantyny/delta"
def get_content():
page = requests.get(get_url())
page.encoding = 'UTF-8'
source = prepare_bs(page)
url = source.find_all("link", { "as": "script" })[1]['href']
# print(url)
kantyna = requests.get(url)
kantyna.encoding = 'UTF-8'
# print(kantyna)
return kantyna
def prepare_bs(kantyna):
if kantyna is not None:
html = kantyna.text
soup = BeautifulSoup(html, 'html.parser')
return soup
else:
return "Error"
def get_name():
return "Lunchbox Delta"
def return_menu(soup):
items = []
date = soup.find("h2").text.strip()
a = soup.find_all("li")
for item in a:
parts = item.find_all("p")
nazev = parts[0].text.strip()
cena = parts[2].text.strip(" [Kk]č").strip()
if nazev and cena:
arr = [nazev, str(cena) + " Kč"]
items.append(arr)
return (date, items)
def debug_print(date, menu):
print(date)
print(menu)
def result():
lokalita = "brumlovka"
try:
#page = get_file()
page = get_content()
bs = prepare_bs(page)
date, menu_list = return_menu(bs)
nazev = get_name()
url = get_url()
return (nazev, url, date, menu_list, lokalita)
except:
#return(get_name() + " - Chyba", "", "Chyba", ["", "", ""])
nazev = get_name()
url = get_url()
return (nazev, url, "Menu nenalezeno", [], lokalita)
os.remove(TMP)
if __name__ == "__main__":
page = get_content()
# print(page)
bs = prepare_bs(page)
# print(bs)
date, menu_list = return_menu(bs)
debug_print(date, menu_list)
#print(result())