-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
71 lines (58 loc) · 2.06 KB
/
app.py
File metadata and controls
71 lines (58 loc) · 2.06 KB
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
from flask import Flask
import requests
from bs4 import BeautifulSoup
app = Flask(__name__)
@app.route('/')
def index(): # put application's code here
response = requests.get('https://fsa-efimeries.gr/')
soup = BeautifulSoup(response.text, 'html.parser')
select = soup.findChildren('select', {'id': 'Date'})
children = select[0].findChildren("option", recursive=False)
date = children[0].text.strip()
response = requests.get('https://fsa-efimeries.gr/Home/FilteredHomeResults')
soup = BeautifulSoup(response.text, 'html.parser')
cards = soup.select(".card-frame")
total_rows = []
keys = [
'-',
'-',
'perioxi',
'farmakeio',
'dieuthinsi',
'tilefono',
'orario',
'katastasi'
]
for card in cards:
title = card.select_one(".card-title h6").get_text(strip=True)
subtitle = card.select_one(".card-subtitle").get_text(strip=True)
pharmacist = card.select_one(".card-text span:nth-of-type(1)").get_text(strip=True)
hours = card.select_one(".card-text span:nth-of-type(2)").get_text(strip=True)
phone = card.select_one(".card-text h6").get_text(strip=True)
status_img = card.select_one("img")
status_src = status_img["src"]
if "anoixto" in status_src:
status = "Ανοιχτό"
elif "kleisto" in status_src:
status = "Κλειστό"
else:
status = "Άγνωστο"
final_row = {
'perioxi': subtitle,
'farmakeio': pharmacist,
'dieuthinsi': title,
'tilefono': phone,
'orario': hours,
'katastasi': status
}
total_rows.append(final_row)
#
pharmacies = []
districts = []
for farmakeio_row in total_rows:
if farmakeio_row['perioxi'] not in districts:
districts.append(farmakeio_row['perioxi'])
pharmacies.append(farmakeio_row)
return {'date': date, 'districts': districts, 'pharmacies': pharmacies}
if __name__ == '__main__':
app.run()