Spaces:
Running
Running
| """Fix the one failed listing by geocoding just the city""" | |
| import asyncio | |
| from app.database import connect_db, get_db | |
| from app.ai.tools.listing_tool import geocode_address | |
| from bson import ObjectId | |
| async def fix_failed_listing(): | |
| await connect_db() | |
| db = await get_db() | |
| # Find the specific listing | |
| listing_id = "694402f3947fa344b4462fce" | |
| print("π Geocoding Cotonou (city only)...") | |
| geo_result = await geocode_address("Cotonou", None) | |
| if geo_result.get("success"): | |
| lat = geo_result.get("latitude") | |
| lon = geo_result.get("longitude") | |
| result = await db.listings.update_one( | |
| {"_id": ObjectId(listing_id)}, | |
| {"$set": {"latitude": lat, "longitude": lon}} | |
| ) | |
| if result.modified_count > 0: | |
| print(f"β Updated: lat={lat}, lon={lon}") | |
| else: | |
| print("β οΈ No change made") | |
| else: | |
| print(f"β Failed: {geo_result.get('error')}") | |
| if __name__ == "__main__": | |
| asyncio.run(fix_failed_listing()) | |