Skip to content

Commit

Permalink
count the number of removed listings
Browse files Browse the repository at this point in the history
  • Loading branch information
perfectly-preserved-pie committed Jul 8, 2024
1 parent 9f51e07 commit a44f381
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions functions/dataframe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
async def remove_expired_listings(df: pd.DataFrame, limiter: AsyncLimiter) -> pd.DataFrame:
"""
Asynchronously checks each listing URL in the DataFrame to determine if it has expired,
and removes rows with expired listings, applying rate limiting.
and removes rows with expired listings, applying rate limiting. Also counts the number of expired listings removed.
Parameters:
df (pd.DataFrame): The DataFrame containing listing URLs and MLS numbers.
Expand All @@ -32,11 +32,16 @@ async def check_and_mark_expired(row):
# Determine indexes of rows to drop (where listing has expired)
indexes_to_drop = [index for index, expired in results if expired]

# Log success messages for dropped listings
# Counter for expired listings
expired_count = len(indexes_to_drop)

# Log success messages for dropped listings and the count of expired listings
for index in indexes_to_drop:
mls_number = df.loc[index, 'mls_number']
logger.success(f"Removed {mls_number} (Index: {index}) from the dataframe because the listing has expired.")

logger.info(f"Total expired listings removed: {expired_count}")

# Drop the rows from the DataFrame and return the modified DataFrame
df_dropped_expired = df.drop(indexes_to_drop)
return df_dropped_expired

0 comments on commit a44f381

Please sign in to comment.