forked from dgunning/edgartools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_raw_facts.py
More file actions
120 lines (92 loc) · 4.09 KB
/
debug_raw_facts.py
File metadata and controls
120 lines (92 loc) · 4.09 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""
Debug raw facts data structure to understand why shares outstanding isn't found
Usage:
python debug_raw_facts.py MSFT
"""
import argparse
from edgar import Company, set_identity
set_identity("Dev Gunning developer-gunning@gmail.com")
def debug_raw_facts(ticker: str):
"""Inspect the raw facts object structure."""
company = Company(ticker)
print(f"\n{'='*80}")
print(f"RAW FACTS INSPECTION: {ticker} ({company.name})")
print(f"{'='*80}\n")
try:
facts = company.get_facts()
# Show facts object type and structure
print(f"Facts object type: {type(facts)}")
print(f"Facts attributes: {dir(facts)}\n")
# Try to access raw data
if hasattr(facts, 'facts'):
print(f"✓ Has 'facts' attribute")
print(f" Type: {type(facts.facts)}")
# If it's a dict, show keys
if isinstance(facts.facts, dict):
print(f" Keys: {list(facts.facts.keys())[:10]}")
# Look for share-related concepts
share_keys = [k for k in facts.facts.keys() if 'share' in k.lower() or 'stock' in k.lower()]
print(f"\n Share-related concepts ({len(share_keys)} found):")
for key in share_keys[:20]:
print(f" - {key}")
# Check if it has a data attribute
if hasattr(facts, 'data'):
print(f"\n✓ Has 'data' attribute")
print(f" Type: {type(facts.data)}")
# Try the query method directly with debugging
print(f"\n{'='*80}")
print("TESTING QUERY API")
print(f"{'='*80}\n")
concepts_to_test = [
'us-gaap:CommonStockSharesOutstanding',
'CommonStockSharesOutstanding',
'us-gaap:WeightedAverageNumberOfSharesOutstandingBasic',
'WeightedAverageNumberOfSharesOutstandingBasic'
]
for concept in concepts_to_test:
print(f"\nTesting concept: {concept}")
try:
# Try without any filters
result = facts.query().by_concept(concept).execute()
print(f" Result (no filters): {len(result) if result else 0} facts")
if result and len(result) > 0:
print(f" First fact: {result[0]}")
print(f" Value: {result[0].numeric_value if hasattr(result[0], 'numeric_value') else 'N/A'}")
print(f" Date: {result[0].end_date if hasattr(result[0], 'end_date') else 'N/A'}")
# Try with latest
result = facts.query().by_concept(concept).latest(1).execute()
print(f" Result (latest): {len(result) if result else 0} facts")
if result and len(result) > 0:
print(f" Value: {result[0].numeric_value if hasattr(result[0], 'numeric_value') else 'N/A'}")
except Exception as e:
print(f" ❌ Error: {str(e)[:150]}")
# Try to get facts using alternative access patterns
print(f"\n{'='*80}")
print("ALTERNATIVE ACCESS PATTERNS")
print(f"{'='*80}\n")
# Try direct attribute access
try:
if hasattr(facts, 'get_facts'):
print("✓ Has get_facts() method")
result = facts.get_facts()
print(f" Result type: {type(result)}")
except Exception as e:
print(f"❌ get_facts() error: {e}")
# Try accessing by standard concept names
try:
# Check what methods are available
methods = [m for m in dir(facts) if not m.startswith('_')]
print(f"\nAvailable methods: {methods[:10]}...")
except Exception as e:
print(f"❌ Error: {e}")
except Exception as e:
print(f"❌ Error accessing facts: {e}")
import traceback
traceback.print_exc()
def main():
parser = argparse.ArgumentParser(description='Debug raw facts data structure')
parser.add_argument('ticker', help='Company ticker symbol')
args = parser.parse_args()
debug_raw_facts(args.ticker)
if __name__ == "__main__":
main()