"""
Example script demonstrating how to search for obesity drugs using the local WebSocket server.
"""
import asyncio
import json
import websockets
async def search_drugs(query):
"""Search for drugs using the local WebSocket server."""
async with websockets.connect('ws://localhost:8765') as websocket:
# Send the search request
request = {
"jsonrpc": "2.0",
"method": "search_drugs",
"params": query,
"id": 1
}
await websocket.send(json.dumps(request))
# Get the response
response = await websocket.recv()
return json.loads(response)
async def main():
# Search for Phase 3 obesity drugs
phase3_query = {
"indication": "obesity",
"phase": "C3" # Phase 3 Clinical
}
phase3_results = await search_drugs(phase3_query)
print("\nPhase 3 Obesity Drugs:")
print(json.dumps(phase3_results, indent=2))
# Search for launched obesity drugs
launched_query = {
"indication": "obesity",
"phase": "L" # Launched
}
launched_results = await search_drugs(launched_query)
print("\nLaunched Obesity Drugs:")
print(json.dumps(launched_results, indent=2))
# Search for specific company's obesity drugs
company_query = {
"company": "Novo Nordisk",
"indication": "obesity"
}
company_results = await search_drugs(company_query)
print("\nNovo Nordisk Obesity Drugs:")
print(json.dumps(company_results, indent=2))
if __name__ == "__main__":
asyncio.run(main())