Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Airbnb/__pycache__/location.cpython-310.pyc
Binary file not shown.
Binary file added Airbnb/__pycache__/model.cpython-310.pyc
Binary file not shown.
112 changes: 112 additions & 0 deletions Airbnb/airbnb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import requests
from datetime import datetime, timedelta
import pandas as pd
from location import get_location
from model import main_model

def data_parse(location):
url = "https://airbnb13.p.rapidapi.com/search-location"
today = datetime.now().date()

# Format today's date as yyyy-mm-dd
formatted_today = today.strftime('%Y-%m-%d')

# Add 2 weeks to today's date
two_weeks_extra = today + timedelta(weeks=2)

# Format the date after adding 2 weeks as yyyy-mm-dd
formatted_two_weeks_extra = two_weeks_extra.strftime('%Y-%m-%d')

querystring = {"location":location,"checkin":formatted_today,"checkout":formatted_two_weeks_extra,"adults":"2","children":"0","infants":"0","pets":"0","page":"1","currency":"INR"}

headers = {
##enter your api key here
"X-RapidAPI-Key":'' ,
"X-RapidAPI-Host":''
}



response = requests.get(url, headers=headers, params=querystring)
t=response.json()
h=t['headers']
if h['response_id']:
print('Data Fetched')
return t


def convert_csv(data):
values=data["results"]
array=[]
for option in values:
new=[]
try:
r=option['rating']
except:
r=2.5
try:
new.append(option['url'])
except:
new.append('No URL Available')
try:
new.append(option['deeplink'])
except:
new.append("No link available")
try:
new.append(option['position'])
except:
new.append(0)
try:
new.append(option['name'])
except:
new.append('No name available')
try:
new.append(option['bathrooms'])
except:
new.append(0)
try:
new.append(option['bedrooms'])
except:
new.append(0)
try:
new.append(option['beds'])
except:
new.append(0)
try:
new.append(option['images'])
except:
new.append('No image avalable')
try:
loc=get_location(option['lat'], option['lng'])
location=[loc]
new.append(location)
except:
new.append('No location availble')
try:
new.append(option['persons'])
except:
new.append(1)
# new.append(option['rating'])
new.append(r)
new.append(option['type'])
new.append(option['previewAmenities'])
costings=option['price']
new.append(int(costings['total'])/14)
array.append(new)


df=pd.DataFrame(array)
columns_names=['url', 'link', 'position', 'name', 'bathrooms', 'bedrooms','beds', 'images', 'location', 'no_of_persons_allowed', 'rating', 'type', 'ammenities', 'price_in_rupees']
df.columns=columns_names
with open("content.txt", 'w') as file:
file.write(str(df))
return df

if __name__=="__main__":
city=input("Enter the city to explore ")
# date=str(input("Enter the date of arrival in yyyy-mm-dd "))
# stay_period=int(input("No of days you want to stay "))
data=data_parse(city)
modified_data=convert_csv(data)
main_model(modified_data)
# print(data)
Binary file added Airbnb/chromedriver/chromedriver.exe
Binary file not shown.
43 changes: 43 additions & 0 deletions Airbnb/content.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
url ... price_in_rupees
0 https://www.airbnb.com/rooms/43808076 ... 1329.214286
1 https://www.airbnb.com/rooms/1071561081334981451 ... 1765.571429
2 https://www.airbnb.com/rooms/685122089704721378 ... 1930.571429
3 https://www.airbnb.com/rooms/875017321059559852 ... 1854.857143
4 https://www.airbnb.com/rooms/950492274215534501 ... 1409.214286
5 https://www.airbnb.com/rooms/820713392508700078 ... 2756.571429
6 https://www.airbnb.com/rooms/877524107867346429 ... 2753.071429
7 https://www.airbnb.com/rooms/46860357 ... 1310.428571
8 https://www.airbnb.com/rooms/30300931 ... 4046.857143
9 https://www.airbnb.com/rooms/753202607734629206 ... 3138.785714
10 https://www.airbnb.com/rooms/46806787 ... 2090.714286
11 https://www.airbnb.com/rooms/1086007621463359203 ... 2211.714286
12 https://www.airbnb.com/rooms/1024464266230385449 ... 2773.785714
13 https://www.airbnb.com/rooms/646177131671993427 ... 3136.000000
14 https://www.airbnb.com/rooms/701046475355640691 ... 2956.428571
15 https://www.airbnb.com/rooms/1125721477299318510 ... 2272.000000
16 https://www.airbnb.com/rooms/838058378099542611 ... 2145.785714
17 https://www.airbnb.com/rooms/910132291975354672 ... 3683.357143
18 https://www.airbnb.com/rooms/929268613305037760 ... 2239.142857
19 https://www.airbnb.com/rooms/765013693234574079 ... 3131.214286
20 https://www.airbnb.com/rooms/702467172768452858 ... 2916.500000
21 https://www.airbnb.com/rooms/31110618 ... 1329.214286
22 https://www.airbnb.com/rooms/54321361 ... 1360.785714
23 https://www.airbnb.com/rooms/1085966060486502774 ... 2211.714286
24 https://www.airbnb.com/rooms/595267110809242119 ... 2819.571429
25 https://www.airbnb.com/rooms/1024520370492574679 ... 2773.785714
26 https://www.airbnb.com/rooms/950501857031794752 ... 1432.142857
27 https://www.airbnb.com/rooms/1096815922979532740 ... 2085.285714
28 https://www.airbnb.com/rooms/1127830853582407942 ... 3982.500000
29 https://www.airbnb.com/rooms/1071621663125894904 ... 1608.857143
30 https://www.airbnb.com/rooms/988232548011031670 ... 1697.357143
31 https://www.airbnb.com/rooms/54169925 ... 2090.785714
32 https://www.airbnb.com/rooms/654813497648401928 ... 2016.000000
33 https://www.airbnb.com/rooms/1011979815750155572 ... 1622.928571
34 https://www.airbnb.com/rooms/45820565 ... 1904.000000
35 https://www.airbnb.com/rooms/1081902748211422002 ... 1449.714286
36 https://www.airbnb.com/rooms/47332070 ... 2060.785714
37 https://www.airbnb.com/rooms/728159173582211488 ... 2325.571429
38 https://www.airbnb.com/rooms/46931902 ... 2097.571429
39 https://www.airbnb.com/rooms/52761188 ... 2045.357143

[40 rows x 14 columns]
52 changes: 52 additions & 0 deletions Airbnb/data_collect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from bs4 import BeautifulSoup
import time

# Function to extract details using BeautifulSoup
def extract_details(html_content):
soup = BeautifulSoup(html_content, 'html.parser')
# Modify this part according to the structure of the website to extract the required details
details = soup.find_all('div', class_='m-srp-card__desc flex__item')
for detail in details:
print(detail.text.strip())
print("Total {} details found.".format(len(details)))

# Configure Chrome options
chrome_options = webdriver.ChromeOptions()

# Path to your ChromeDriver executable
# chrome_driver_path = "C:/Users/colle/OneDrive/Desktop/Internship/Nuevera/Various_models/chromedriver/chromedriver.exe"

driver = webdriver.Chrome(options=chrome_options)

# Open the Magicbricks website
city='bengaluru'
driver.get(f"https://www.magicbricks.com/property-for-sale/residential-real-estate?bedroom=2,3&proptype=Multistorey-Apartment,Builder-Floor-Apartment,Penthouse,Studio-Apartment,Residential-House,Villa&cityName=${city}")

# Wait for the website to load
# time.sleep(5) # Adjust the waiting time according to the website's loading speed

# Find the search box and enter the city details
# clear_box = driver.find_element("xpath", '//*[@class="mb-search__tag-t"]')
# clear_box.send_keys('')
# search_box = driver.find_element("xpath", '//*[@class="mb-search__input"]')
# search_box.send_keys("Bengaluru") # Replace "Enter City Name" with the desired city name
# search_box.send_keys(Keys.RETURN)
# Wait for the search results to load
time.sleep(10) # Adjust the waiting time according to the website's loading speed

page_content = driver.page_source

# Print the whole content
print(page_content)

# Get the HTML content of the page
# html_content = driver.page_source

# # Extract details using BeautifulSoup
# extract_details(html_content)

# Close the WebDriver session
driver.quit()
Loading