-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_keyword_api.py
More file actions
90 lines (71 loc) · 2.82 KB
/
debug_keyword_api.py
File metadata and controls
90 lines (71 loc) · 2.82 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
#!/usr/bin/env python3
"""
Debug script to check DataForSEO keyword API response
"""
import json
from src.mcp_seo.config.settings import get_language_code, get_location_code
from src.mcp_seo.dataforseo.client import DataForSEOClient
def main():
# Initialize client
client = DataForSEOClient()
# Test keywords
keywords = ["python code analyzer", "python dependency analysis"]
location = "United States"
language = "en"
location_code = get_location_code(location)
language_code = get_language_code(language)
print(f"Testing keyword API with:")
print(f" Keywords: {keywords}")
print(f" Location: {location} (code: {location_code})")
print(f" Language: {language} (code: {language_code})")
print("\n" + "=" * 80 + "\n")
# Make API request
print("Step 1: Creating keyword task...")
result = client.get_keyword_data(
keywords=keywords, location_code=location_code, language_code=language_code
)
print("Initial Response:")
print(json.dumps(result, indent=2))
print("\n" + "=" * 80 + "\n")
if not result.get("tasks"):
print("ERROR: No tasks in response!")
return
task_id = result["tasks"][0]["id"]
print(f"Task ID: {task_id}")
print(f"Task Status: {result['tasks'][0].get('status_message')}")
print("\n" + "=" * 80 + "\n")
# Wait for completion
print("Step 2: Waiting for task completion...")
completed_result = client.wait_for_task_completion(task_id, "keywords")
print("Completed Response:")
print(json.dumps(completed_result, indent=2))
print("\n" + "=" * 80 + "\n")
# Check result structure
if completed_result.get("tasks"):
task = completed_result["tasks"][0]
print("Task Info:")
print(f" Status Code: {task.get('status_code')}")
print(f" Status Message: {task.get('status_message')}")
print(f" Cost: {task.get('cost')}")
if task.get("result"):
print(f"\nResult Info:")
print(f" Number of result entries: {len(task['result'])}")
if task["result"]:
first_result = task["result"][0]
print(f" First result keys: {list(first_result.keys())}")
print(f" Items count: {len(first_result.get('items', []))}")
if first_result.get("items"):
print(f"\nFirst item sample:")
print(json.dumps(first_result["items"][0], indent=2))
else:
print(f"\nWARNING: Items array is EMPTY!")
print(f"Full first result:")
print(json.dumps(first_result, indent=2))
else:
print("\nERROR: No result in task!")
else:
print("ERROR: No tasks in completed response!")
if __name__ == "__main__":
main()
if __name__ == "__main__":
main()