-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_agents.py
More file actions
59 lines (43 loc) · 1.81 KB
/
Copy path06_agents.py
File metadata and controls
59 lines (43 loc) · 1.81 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
"""
Search real estate agents by area.
python examples/06_agents.py
Note the agent endpoints use snake_case field names (agent_name_en,
agency_name_en) rather than the camelCase used by the property endpoints, and
return a plain list rather than an object with a total.
"""
from dotenv import load_dotenv
from bayut import BayutClient
load_dotenv()
def badges(agent):
"""TruBroker and related quality flags come back as "1" or "0" strings."""
labels = {
"is_trubroker_badge_prev_month": "TruBroker",
"is_responsive_agent_badge_prev_month": "Responsive",
"is_quality_lister_badge_prev_month": "Quality Lister",
}
return [label for key, label in labels.items() if str(agent.get(key)) == "1"]
def main():
client = BayutClient()
agents = client.search_agents(location_id="5003", purpose="for-sale")
print(f"Found {len(agents)} agents in Dubai Marina\n")
for agent in agents[:10]:
name = agent.get("agent_name_en") or "Unknown"
agency = agent.get("agency_name_en") or "Independent"
emirate = agent.get("most_active_emirate_prev_month") or "-"
earned = badges(agent)
print(f"{name}")
print(f" {agency} | most active in {emirate}")
if earned:
print(f" Badges: {', '.join(earned)}")
print(f" Agent ID: {agent.get('agent_external_id')}")
print()
# Agencies represented, ranked by how many of these agents they employ.
agencies = {}
for agent in agents:
agency = agent.get("agency_name_en") or "Independent"
agencies[agency] = agencies.get(agency, 0) + 1
print("Agencies by agent count in this result set:")
for agency, count in sorted(agencies.items(), key=lambda kv: -kv[1])[:8]:
print(f" {count:>3} {agency}")
if __name__ == "__main__":
main()