File size: 2,065 Bytes
26c5c2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
"""
Fetch raw valuation data from Yahoo Finance and Alpha Vantage.
Outputs the data schema with actual values.
"""

import asyncio
import json
import sys
sys.path.insert(0, '/home/vn6295337/Researcher-Agent')

from mcp_client import call_mcp_server


async def fetch_valuation(ticker: str = 'AAPL'):
    """Fetch valuation from Yahoo Finance and Alpha Vantage."""
    result = await call_mcp_server(
        'valuation-basket',
        'get_all_sources_valuation',
        {'ticker': ticker},
        timeout=90
    )
    return result


def print_schema(data: dict, ticker: str):
    """Print data schema in plain text format."""
    print("Yahoo Finance & Alpha Vantage Valuation Data Schema")
    print("=" * 50)
    print(f"\nExample Ticker: {ticker}")
    print()

    for source_key in ['yahoo_finance', 'alpha_vantage']:
        if source_key in data:
            source_data = data[source_key]
            source_name = source_data.get('source', source_key)

            print(f"\n{source_name}")
            print("-" * 40)
            print(f"source: {source_name}")
            print(f"as_of: {source_data.get('as_of')}")

            metrics = source_data.get('data', {})
            for key, val in metrics.items():
                print(f"\n  {key}")
                if isinstance(val, dict):
                    for k, v in val.items():
                        print(f"    {k}: {v}")
                else:
                    print(f"    value: {val}")


async def main():
    ticker = sys.argv[1] if len(sys.argv) > 1 else 'AAPL'

    print(f"Fetching valuation for {ticker}...")
    data = await fetch_valuation(ticker)

    if data:
        print_schema(data, ticker)

        # Also save raw JSON
        with open(f'/home/vn6295337/Researcher-Agent/docs/{ticker}_valuation_raw.json', 'w') as f:
            json.dump(data, f, indent=2, default=str)
        print(f"\nRaw JSON saved to: docs/{ticker}_valuation_raw.json")
    else:
        print("Failed to fetch data")


if __name__ == '__main__':
    asyncio.run(main())