Skip to content

Commit

Permalink
Added support for neighbourhoods in db
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivamSingal committed Jan 16, 2024
1 parent 8b134af commit 5e83096
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion backend/app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

SQLALCHEMY_DATABASE_URL = os.getenv("DATABASE_URL")

engine = create_engine(SQLALCHEMY_DATABASE_URL)
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
pool_pre_ping=True,
pool_recycle=300
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()
1 change: 1 addition & 0 deletions backend/app/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Building(Base):
autoincrement=True, unique=True)
name = Column(String, index=True)
address = Column(String, index=True)
neighbourhood = Column(String, index=True)
city = Column(String, index=True)
lat = Column(Float, primary_key=True)
lon = Column(Float, primary_key=True)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/pydantic_schemas/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AddListing(BaseModel):
bath: float
sqft: float
price: float
pets: float
pets: bool
latitude: float
longitude: float
date: datetime
Expand Down
3 changes: 2 additions & 1 deletion backend/app/scripts/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
session.query(Building).delete()

# Recreate tables after dropping them (if needed)
Base.metadata.create_all(engine)
# Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)

# Commit changes and close the session
session.commit()
Expand Down
1 change: 1 addition & 0 deletions backend/app/services/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def row_to_building(row, db: Session) -> Building:
return Building(
name=row[TableHeaders.BUILDING.value],
address=row[TableHeaders.ADDRESS.value],
neighbourhood = row[TableHeaders.NEIGHBOURHOOD.value],
city=row[TableHeaders.CITY.value],
lat=row[TableHeaders.LAT.value],
lon=row[TableHeaders.LON.value],
Expand Down
Binary file modified data/cleaned_data/01-01-2024_cleaned_listings.xlsx
Binary file not shown.
Binary file modified data/cleaned_data/01-12-2023_cleaned_listings.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion data/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def create_chrome_driver(*, debugging_port):
chrome_options.add_argument(f"user-agent={user_agent}")
chrome_options.add_argument(f"--remote-debugging-port={debugging_port}")
chrome_options.add_argument('--window-size=1920x1080')
# chrome_options.add_argument("--headless") # Enable headless mode (does not open browser GUI)
chrome_options.add_argument("--headless") # Enable headless mode (does not open browser GUI)

# First ChromeService instance
chrome_service = ChromeService(executable_path=chrome_driver_path)
Expand Down
4 changes: 1 addition & 3 deletions data/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ def extract_raw_data(filepath: str, listing_urls: list[str]) -> pd.DataFrame:
file.write('\n'.join(padmapper_scraper.urls))

current_100_units = []
current_city_units = []

# Scrape page content of collected URLs to get rental listing data
for url in padmapper_scraper.urls:
try:
# on every 100 listings read, write them to the excel sheet (in case of crash)
if len(current_100_units) >= 100:
current_city_units += current_100_units
extracted_listing_data += current_city_units
extracted_listing_data += current_100_units
extracted_listing_data_df = pd.DataFrame(extracted_listing_data, columns=table_columns)
extracted_listing_data_df.to_excel(filepath, index=False)
current_100_units.clear()
Expand Down
Binary file added listings.pkl
Binary file not shown.

1 comment on commit 5e83096

@vercel
Copy link

@vercel vercel bot commented on 5e83096 Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.