-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebscrapper
More file actions
737 lines (602 loc) · 23.5 KB
/
webscrapper
File metadata and controls
737 lines (602 loc) · 23.5 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
# -*- coding: utf-8 -*-
"""Copy of Mini-project-1-Debayan.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1U1rCxhS2iPk_WSM1QyebCkGz1J1xzjaE
Please read this instruction before running this notebook, or else there might be error. These websites were scrapped and visualized on a certain time so the data might get changed in a while making it difficult to read and process:
PLEASE RUN ONLY THE BELOW PORTIONS AS NEEDED
AT FIRST THE SCRAPPING HAPPENS
THEN THE VISUALIZATION
THEN THE USER INTERACTION
**Ignore all the print statements apart from the user interaction part which is at the bottom (2nd last)**
Run one by one
A1 - This only initializes the code
"""
# Commented out IPython magic to ensure Python compatibility.
from bs4 import BeautifulSoup
import requests
import csv
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
# %matplotlib inline
link2= 'https://www.booking.com/searchresults.en-gb.html?label=gen173nr-1FCAEoggI46AdIM1gEaEiIAQGYAQm4AQfIAQzYAQHoAQH4AQuIAgGoAgO4AsXZrJkGwAIB0gIkZmZlZGRjMDItOWU5My00MmJmLWJmZmUtZDZhYWFmMmQxNWE32AIG4AIB&sid=44ac8de6d5475c2eb18761e39631bacd&aid=304142&ss=Paris&ssne=Paris&ssne_untouched=Paris&lang=en-gb&sb=1&src_elem=sb&src=searchresults&dest_id=-1456928&dest_type=city&checkin=2022-12-03&checkout=2022-12-04&group_adults=2&no_rooms=1&group_children=0&sb_travel_purpose=leisure&offset=100'
# Create the pandas DataFrame
df= pd.DataFrame(columns=['Name','Hotels_Address','Distance_from_city_center','Price','Review_Score','Hotel_Rating','Hotel_Summary','Photos'])
#print(df.head())
##
"""A2 -The will scrap the data from booking.com"""
source = requests.get(link2, headers={
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
}).text
#source = requests.get(link5).text
soup = BeautifulSoup(source, 'lxml')
#print(soup.find("section", attrs={"data-stid":"section-results"}).text)
#print(soup.find_all("div", attrs={"data-testid":"property-card"}))
#print(soup.find("div", attrs={"data-testid":"property-card"}).text)
#print(soup)
for Post in soup.find_all('div', attrs={"data-testid":"property-card"}):
#print("New Entry")
print("********")
#print("")
try:
name = Post.h3.text
name= name.replace('Opens in new window', '')
#print(name) r
#print('')
except:
name=''
print(name)
#print('')
try:
#print("inside dist try")
distance = Post.find('span', attrs={"data-testid":"distance"})
dist= str(distance)
dist= dist.replace('<span aria-expanded="false" data-testid="distance">', '')
dist= dist.replace('miles from centre</span>', '')
dist= dist.replace('km from centre</span>', '')
#print(dist) r
#print('')
except:
print("inside dist except")
distance=''
print(distance)
print('')
try:
#print("inside price try")
price_full = Post.find('span', class_='bd73d13072')
price= str(price_full)
price= price.replace('<span class="fcab3ed991 bd73d13072">US$', '')
price= price.replace('</span>', '')
#print(price) r
#print('')
except:
print("inside price except")
price=''
print(price)
print('')
try:
#print("inside review try")
review_full = Post.find('div', class_='d10a6220b4').text
#review= str(review_full)
#review= review.replace('<div aria-label="Scored 8.4 " class="b5cd09854e d10a6220b4">', '')
#review= review.replace('</div>', '')
#print(review_full) r
#print('')
except:
print("inside review except")
review=''
print(review)
print('')
try:
#print("inside rating try")
rating_full = Post.find('div', class_='fbb11b26f5')
rating_str= str(rating_full)
rating= rating_str.count('class="b6dc9a9e69 adc357e4f1 fe621d6382')
#review= review.replace('<div aria-label="Scored 8.4 " class="b5cd09854e d10a6220b4">', '')
#review= review.replace('</div>', '')
#print(rating) r
#print('')
except:
print("inside rating except")
rating=''
print(rating)
print('')
#try:
#print("inside hotel_link try ")
hotel_link_full= Post.find('a', attrs={"data-testid":"title-link"})
hotel_link_str= str(hotel_link_full)
hotel_link= hotel_link_str.replace('<a class="e13098a59f" data-testid="title-link" href="', '')
hotel_link= hotel_link.replace('" rel="noopener noreferrer" target="_blank"><div class="fcab3ed991 a23c043802" data-testid="title">', '')
hotel_link= hotel_link.replace(name, '')
hotel_link= hotel_link.replace('</div><div class="e6e585da68">Opens in new window</div></a>', '')
#print(hotel_link)
source_hotel = requests.get(hotel_link, headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",}).text
soup_hotel = BeautifulSoup(source_hotel, 'lxml')
#print("")
#print(soup_hotel)
address_full=soup_hotel.find('p', class_='address address_clean').text
address_str=str(address_full)
address = address_str.replace("\n", "")
address = address.split("–")[0]
address.strip()
#rem= address.split(", ")[-1]
#address = address.replace(rem, "")
#print(address) r
description_full= soup_hotel.find('div', attrs={"id":"property_description_content"}).text
description_cut = "You're eligible for a Genius discount at " +name + "! To save at this property, all you have to do is sign in."
description_full= description_full.replace(description_cut,"")
description_full = description_full.replace("\n","")
#print(description_full) r
image_link_full = soup_hotel.find_all('div', class_='bh-photo-grid-thumb-cell')
#image_link= image_link_full.find(attrs={"id":"property_description_content"})
#image_link=[]
#image_link =image_link.append(image_link_full.find_all('img')['src'])
image_list =[]
for parts in image_link_full:
image= parts.a["style"]
image= image.replace("background-image: url(","")
image= image.replace(");","")
#print(image)
image_list.append(image)
#print(image_list)
#print("")
#print('')
#except:
#print("inside hotel_link except")
#address=''
#print(address)
#description=''
#print(description)
#print('')
#print(image_list) real
new_row = {'Name':name, 'Hotels_Address':address, 'Distance_from_city_center':dist, 'Price':price,'Review_Score':review_full,'Hotel_Rating':rating,'Hotel_Summary':description_full,'Photos':image_list}
df = df.append(new_row, ignore_index=True)
#print(new_row)
#image_list.clear()
#print('')
#df.to_csv('file_name2.csv')
#df.isnull().sum()
#df['Distance_from_city_center'] = pd.to_numeric(df['Distance_from_city_center'])
#df['Price'] = pd.to_numeric(df['Price'])
#df['Review_Score'] = pd.to_numeric(df['Review_Score'])
#df['Hotel_Rating'] = pd.to_numeric(df['Hotel_Rating'])
"""A3 this will scrap edreams.com"""
dream_link= 'https://hotels.edreams.com/searchresults.html?aid=350435&checkin=2022-12-03&checkout=2022-12-04&fp_referrer_aid=1171464&group_adults=2&group_children=0&label=edr-link-com-seosearchbox-conf-pc-of&lang=en-gb&no_rooms=1&selected_currency=EUR&si=ai%2Cco%2Cci%2Cre%2Cdi&sp_plprd=UmFuZG9tSVYkc2RlIyh9YVXcKaaJl1ClqALJLPfcxMrW3cUtpQCJICXxCeUszNb7HtaQDpi3MeNBJjBUql2B1yFndp5hdoYRzhIkih17O_TCCala4AsWUIQxULxzWpQy6JBoMk09AhHlSAAttaCvYw&ss=Paris&submit=Search+hotels&utm_campaign=sb4&utm_medium=sp&utm_source=AW_Searchbox'
dream_source = requests.get(dream_link, headers={
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
}).text
dream_soup= BeautifulSoup(dream_source, 'lxml')
#print(dream_soup)
for Post in dream_soup.find_all('div', attrs={"data-testid":"property-card"}):
print("New Entry")
print("********")
print("")
try:
name = Post.h3.text
name= name.replace('Opens in new window', '')
print(name)
#print('')
except:
name=''
print(name)
print('')
try:
#print("inside dist try")
distance = Post.find('span', attrs={"data-testid":"distance"})
dist= str(distance)
dist= dist.replace('<span aria-expanded="false" data-testid="distance">', '')
dist= dist.replace('miles from centre</span>', '')
dist= dist.replace('km from centre</span>', '')
print(dist)
#print('')
except:
print("inside dist except")
distance=''
print(distance)
print('')
try:
#print("inside price try")
price_full = Post.find('span', class_='bd73d13072')
price= str(price_full)
price= price.replace('<span class="fcab3ed991 bd73d13072">US$', '')
price= price.replace('</span>', '')
print(price)
#print('')
except:
print("inside price except")
price=''
print(price)
print('')
try:
#print("inside review try")
review_full = Post.find('div', class_='d10a6220b4').text
#review= str(review_full)
#review= review.replace('<div aria-label="Scored 8.4 " class="b5cd09854e d10a6220b4">', '')
#review= review.replace('</div>', '')
print(review_full)
#print('')
except:
print("inside review except")
review=''
print(review)
print('')
try:
#print("inside rating try")
rating_full = Post.find('div', class_='fbb11b26f5')
rating_str= str(rating_full)
rating= rating_str.count('class="b6dc9a9e69 adc357e4f1 fe621d6382')
#review= review.replace('<div aria-label="Scored 8.4 " class="b5cd09854e d10a6220b4">', '')
review= review.replace('</div>', '')
#print(rating)
#print('')
except:
print("inside rating except")
rating=''
#print(rating)
#print('')
hotel_link_full= Post.find('a', attrs={"data-testid":"title-link"})
hotel_link_str= str(hotel_link_full)
hotel_link= hotel_link_str.replace('<a class="e13098a59f" data-testid="title-link" href="', '')
hotel_link= hotel_link.replace('" rel="noopener noreferrer" target="_blank"><div class="fcab3ed991 a23c043802" data-testid="title">', '')
hotel_link= hotel_link.replace(name, '')
hotel_link= hotel_link.replace('</div><div class="e6e585da68">Opens in new window</div></a>', '')
#print(hotel_link)
source_hotel = requests.get(hotel_link, headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",}).text
dream_soup_hotel = BeautifulSoup(source_hotel, 'lxml')
#print(soup_hotel)
address_full=dream_soup_hotel.find('p', class_='address address_clean').text
address_str=str(address_full)
address = address_str.replace("\n", "")
address = address.split("–")[0]
address.strip()
#rem= address.split(", ")[-1]
#address = address.replace(rem, "")
print(address)
description_full= dream_soup_hotel.find('div', attrs={"id":"property_description_content"}).text
description_cut = "You're eligible for a Genius discount at " +name + "! To save at this property, all you have to do is sign in."
description_full= description_full.replace(description_cut,"")
description_full = description_full.replace("\n","")
print(description_full)
image_link_full = dream_soup_hotel.find_all('div', class_='bh-photo-grid-thumb-cell')
#image_link= image_link_full.find(attrs={"id":"property_description_content"})
#image_link=[]
#image_link =image_link.append(image_link_full.find_all('img')['src'])
image_list =[]
for parts in image_link_full:
image= parts.a["style"]
image= image.replace("background-image: url(","")
image= image.replace(");","")
print(image)
image_list.append(image)
#print(image_list)
#print("")
new_row = {'Name':name, 'Hotels_Address':address, 'Distance_from_city_center':dist, 'Price':price,'Review_Score':review_full,'Hotel_Rating':rating,'Hotel_Summary':description_full,'Photos':image_list}
df = df.append(new_row, ignore_index=True)
#df.to_csv('file_name3.csv')
"""A4 this will scrap the letsbookhotel.com and will fill the dataframe completely and also create a csv with all the result"""
#lets_link= 'https://www.letsbookhotel.com/en/france/paris/hotels-accommodation.aspx?page='
for i in range(1, 18):
lets_link= 'https://www.letsbookhotel.com/en/france/paris/hotels-accommodation.aspx?page=' + str(i)
lets_source = requests.get(lets_link, headers={
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
}).text
lets_soup= BeautifulSoup(lets_source, 'lxml')
#print(lets_soup)
for Post in lets_soup.find_all('li', class_="hotelitem"):
#print(Post)
print("New Entry")
print("********")
print("")
try:
#print("inside try")
name = Post.find('a',class_="clickable").text
print(name)
#print('')
except:
print("inside except")
name=''
#print(name)
#print('')
try:
#print("inside try")
dist_full = Post.find('div',class_="hoteltitle").text
dist_full= str(dist_full)
dist_full = dist_full.replace("\n","")
dist_full = dist_full.replace("Km > Paris","")
dist_full = dist_full.replace(name,"")
print(dist_full)
#print('')
except:
print("inside except")
dist_full=''
#print(name)
#print('')
try:
#print("inside try")
#rating_full = Post.find('div',class_="hoteltitle")[img]
rating_full= Post.find('img')['alt']
rating_full= str(rating_full)
rating_full = rating_full.replace("stars","")
#rating_full = rating_full.remove("starsm.gif","")
#rating_full = str(rating_full)
#rating_full = rating_full.split('"')[3]
print(rating_full)
#print('')
except:
print("inside except")
rating_full=''
#print(name)
#print('')
try:
address_full= Post.find('span', class_="text icon-text icon-distance").text
address_full = str(address_full)
address_full= address_full.replace("map","")
print(address_full)
except:
address_full=""
try:
info_full= Post.find('div', class_="info").text
info_full= info_full.strip()
info_full= info_full.replace(" ","")
info_full= info_full.replace("/n","")
print(info_full)
except:
info_full=''
try:
price_full = Post.find('div', class_="price").text
price_full = str(price_full)
price_full= price_full.strip()
price_full=price_full.replace("/n","")
price_full=price_full.replace("from US$ ","")
print(price_full)
except:
price_full=""
try:
rev_sco_full = Post.find('div', class_="reviews").text
rev_sco_full= str(rev_sco_full)
rev_sco_full.strip()
rev_sco_full=rev_sco_full.replace(" ","")
rev_sco_full=rev_sco_full.split(".")[0]
num = ""
for c in rev_sco_full:
if c.isdigit():
num = num + c
print(num)
except:
rev_sco_full =''
try:
print("inside soup try")
hotel_link_lets = Post.find('a')['href']
hotel_link_lets = str(hotel_link_lets)
hotel_link_lets = "https://www.letsbookhotel.com" + hotel_link_lets
#print(hotel_link_lets)
source_hotel_lets = requests.get(hotel_link_lets, headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",}).text
soup_hotel_lets = BeautifulSoup(source_hotel_lets, 'lxml')
#print(soup_hotel_lets)
#images_li = soup_hotel_lets.find('div',class_="hotelreview").text
imagess=soup_hotel_lets.find("img", id="contentdisplaypic")["src"]
imagess=str(imagess)
imagess= "https://www.letsbookhotel.com" +imagess
print(imagess)
#for ele in soup_hotel_lets.find_all('div', class_="fotorama__nav fotorama__nav--thumbs fotorama__shadows--right"):
#img=ele.find('img')['src']
#print(ele)
#print(images_li)
#print(soup_hotel_lets)
except:
images=''
new_row = {'Name':name, 'Hotels_Address':address_full, 'Distance_from_city_center':dist_full, 'Price':price_full,'Review_Score':num,'Hotel_Rating':rating_full,'Hotel_Summary':info_full,'Photos':imagess}
df = df.append(new_row, ignore_index=True)
df.to_csv('file_name_with_all_scraped.csv')
#print("out")
#df.isnull().sum()
try:
df['Distance_from_city_center'] = pd.to_numeric(df['Distance_from_city_center'])
df['Price'] = pd.to_numeric(df['Price'])
df['Review_Score'] = pd.to_numeric(df['Review_Score'])
df['Hotel_Rating'] = pd.to_numeric(df['Hotel_Rating'])
except:
print("inside df type conversion except")
df_latest
# Let's calculate the percentage of each hotel star category.
df.Hotel_Rating.value_counts(normalize=True)
#plot the bar graph of percentage hotel star categories
df.Hotel_Rating.value_counts(normalize=True).plot.barh()
plt.show()
#plot the pie chart of Hotel Ratings
df.Hotel_Rating.value_counts(normalize=True).plot.pie()
plt.show()
df.Price.describe()
df.Distance_from_city_center.describe()
#plot the scatter plot of price and review_score v
df.plot.scatter(x="Price",y="Review_Score")
plt.show()
#plot the scatter plot of Hotel_rating and review_score variable in data
df.plot.scatter(x="Hotel_Rating",y="Review_Score")
plt.show()
#plot the scatter plot of price and hotel_rating variable in data
df.plot.scatter(x="Price",y="Hotel_Rating")
plt.show()
#plot the scatter plot of price and distance from city center
df.plot.scatter(x="Price",y="Distance_from_city_center")
plt.show()
#plot the scatter plot of hotel rating and distance from city center
df.plot.scatter(x="Hotel_Rating",y="Distance_from_city_center")
plt.show()
#plot the pair plot of price, rating and distance from city center
sns.pairplot(data = df, vars=['Price','Hotel_Rating','Distance_from_city_center'])
plt.show()
# Creating a matrix using price, Review_score, distance from center as rows and columns
df[['Price', 'Review_Score', 'Distance_from_city_center']].corr()
#plot the correlation matrix
sns.heatmap(df[['Price', 'Review_Score', 'Distance_from_city_center']].corr(), annot=True, cmap = 'Reds')
plt.show()
"""User Interaction , this will also make a result csv with the final result"""
#user_output= pd.read_csv("Booking.csv")
#Userinput
#according to price
print('Please choose price range for hotel that you want from below')
print('1 : 100 Euros or below')
print('2 : 100 Euros - 200 Euros')
print('3 : 200 Euros - 300 Euros')
print('4 : 300 Euros - 400 Euros ')
print('5 : 400 Euros - 500 Euros')
duchoise_price = input('Your Choice =')
if duchoise_price == '1':
dch_price1 = 0
dch_price2 = 100
print(dch_price1, dch_price2)
elif duchoise_price == '2':
dch_price1 = 100
dch_price2 = 200
print(dch_price1, dch_price2)
elif duchoise_price == '3':
dch_price1 = 200
dch_price2 = 300
print(dch_price1, dch_price2)
elif duchoise_price == '4':
dch_price1 = 300
dch_price2 = 400
print(dch_price1, dch_price2)
elif duchoise_price == '5':
dch_price1 = 400
dch_price2 = 500
print(dch_price1, dch_price2)
else:
print('You selected a wrong option')
print('Please choose distance range for hotel from below')
print('1 : 1 miles')
print('2 : 1 miles - 2 miles ')
print('3 : 2 miles - 3 miles ')
print('4 : 3 miles - 4 miles ')
print('5 : 4 miles - 5 miles ')
duchoise_dist = input('Your Choice =')
if duchoise_dist == '1':
dch_dist1 = 0
dch_dist2 = 1
print(dch_dist1,',', dch_dist2)
elif duchoise_dist == '2':
dch_dist1 = 1
dch_dist2 = 2
print(dch_dist1,',', dch_dist2)
elif duchoise_dist == '3':
dch_dist1 = 2
dch_dist2 = 3
print(dch_dist1,',', dch_dist2)
elif duchoise_dist == '4':
dch_dist1 = 3
dch_dist2 = 4
print(dch_dist1,',', dch_dist2)
elif duchoise_dist == '5':
dch_dist1 = 4
dch_dist2 = 5
print(dch_dist1,',', dch_dist2)
else:
print('You selected a wrong option')
#according to hotel review score
print('Please choose review range for hotel from below')
print('1 : 8 or below')
print('2 : 8 - 8.5')
print('3 : 8.5 - 9')
print('4 : 9 - 9.5')
print('5 : 9.5 - 10')
duchoise_review = input('Your Choice =')
if duchoise_review == '1':
dch_review1 = 0
dch_review2 = 8
print(dch_review1,',', dch_review2)
elif duchoise_review == '2':
dch_review1 = 8
dch_review2 = 8.5
print(dch_review1,',', dch_review2)
elif duchoise_review == '3':
dch_review1 = 8.5
dch_review2 = 9
print(dch_review1,',', dch_review2)
elif duchoise_review == '4':
dch_review1 = 9
dch_review2 = 9.5
print(dch_review1,',', dch_review2)
elif duchoise_review == '5':
dch_review1 = 9.5
dch_review2 = 10
print(dch_review1,',', dch_review2)
else:
print('You selected a wrong option')
#accoring to rating
print('Please choose a rating for hotel from below')
print('1 : 1')
print('2 : 2')
print('3 : 3')
print('4 : 4 ')
print('5 : 5')
duchoise_rating = input('Your Choice =')
if duchoise_rating == '1':
dch_rating =1
print(dch_rating)
elif duchoise_rating == '2':
dch_rating =2
print(dch_rating)
elif duchoise_rating == '3':
dch_rating =3
print(dch_rating)
elif duchoise_rating == '4':
dch_rating =4
print(dch_rating)
elif duchoise_rating == '5':
dch_rating =5
print(dch_rating)
else:
print('You selected a wrong option')
#sorting with cols
print('Choose criteria by which you want to sort the data')
print('1 : Distance from the city center')
print('2 : Price')
print('3 : Hotel Rating')
print('4 : Review Score ')
duchoise_col = input('Your Choice =')
if duchoise_col == '1':
dcol_input ='Distance_from_city_center'
print(dcol_input)
elif duchoise_col == '2':
dcol_input ='Price'
print(dcol_input)
elif duchoise_col == '3':
dcol_input ='Review_Score'
print(dcol_input)
elif duchoise_col == '4':
dcol_input ='Hotel_Rating'
print(dcol_input)
else:
print('You selected wrong option')
print(' ********* List of Hotels Names *********')
#df_list=pd.DataFrame(columns=['Name'])
df_new2= pd.DataFrame(columns=['Name','Hotels_Address','Distance_from_city_center','Price','Review_Score','Hotel_Rating','Hotel_Summary','Photos'])
df_new2 = df.loc[(df['Distance_from_city_center']> dch_dist1) & (df['Distance_from_city_center']<=dch_dist2) & (df['Price'] >dch_price1) & (df['Price'] <=dch_price2) & (df['Review_Score']>dch_review1) & (df['Review_Score']<=dch_review2) & (df['Hotel_Rating'] == dch_rating)]
df.sort_values(by=[dcol_input])
#df_new2 = df.loc[(df['Distance_from_city_center']> 0) & (df['Distance_from_city_center']<=8) & (df['Price'] >0) & (df['Price'] <=1000) & (df['Review_Score']>0) & (df['Review_Score']<=100)]
print(df_new2['Name'])
#hotel_name= input('Choose Name of hotel')
print("")
print("")
print("")
print("")
print("")
print('Choose the name of the hotel from the list')
print('Type it exactly as it is')
name_input = input('Your Choice =')
print("")
print("")
print("")
print("")
print(' ********* Details of Hotels *********')
print("")
print("")
print("")
#df_latest=df_new2.where(df_new2['Name'] == name_input)
df_latest= df_new2.loc[(df_new2['Name'] == name_input)]
print(df_latest)
df_latest.to_csv('final_result.csv')
df_latest