-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
116 lines (112 loc) · 3.56 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from date_estimation import CheckDate
from flights import Search
from time_counting import Time
from data_block import TravelPlan
def main(u_from, u_to, d_from, d_to):
"""This function creates html string and save
html file with all data."""
try:
check = CheckDate(d_from, d_to)
except:
er = "Please, enter correct dates."
ht = """
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div style="border:1px solid black;">\
<p style="text-align:center;">{}</p></div>
{}
</body>
</html>
""".format(er, "<br>")
with open("templates/file.html", "w", encoding="utf-8") as file:
file.write(ht)
if check.check_two() is True:
d_from = d_from[0:-2] + "20" + d_from[-2:]
d_to = d_to[0:-2] + "20" + d_to[-2:]
try:
r = Search(u_from, u_to, d_from, d_from)
dd = r.data_extract()
m = Search(u_to, u_from, d_to, d_to)
tt = m.data_extract()
summary = [dd[0][0] + tt[0][0], dd[1], tt[1]]
except:
er = "Sorry there are no flights on your route..."
ht = """
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div style="border:1px solid black;">\
<p style="text-align:center;">{}</p></div>
{}
</body>
</html>
""".format(er, "<br>")
with open("templates/file.html", "w", encoding="utf-8") as file:
file.write(ht)
try:
time = Time(dd, tt)
data1 = dd[0][3] + tt[0][3]
data2 = time.final_route()
travel = TravelPlan(data1, data2, summary)
cities = travel.city_block()
route = "Your route: " + " ==> ".join(cities[1])
st = ""
while not cities[0].isEmpty():
st += '''<div style="border:1px solid black;">\
<p style="text-align:center;">{}</p></div>'''.\
format(cities[0].pop()[1:].replace("\n", "<br><br>"))
st += "\n"
ht = """
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div style="border:1px solid black;">\
<p style="text-align:center;">{}</p></div>
{}
<div style="border:1px solid black;"><center><img src="{}">\
</center></div>
</body>
</html>
""".format(route, st, "static/visual.png")
ht.format(route, st)
with open("templates/file.html", "w", encoding="utf-8") as file:
file.write(ht)
except:
er = "Your date are too short to visit this city."
ht = """
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div style="border:1px solid black;">\
<p style="text-align:center;">{}</p></div>
{}
</body>
</html>
""".format(er, "<br>")
with open("templates/file.html", "w", encoding="utf-8") as file:
file.write(ht)
else:
er = check.check_two()
ht = """
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div style="border:1px solid black;">\
<p style="text-align:center;">{}</p></div>
{}
</body>
</html>
""".format(er, "<br>")
with open("templates/file.html", "w", encoding="utf-8") as file:
file.write(ht)