-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.py
More file actions
53 lines (41 loc) · 1.38 KB
/
basic.py
File metadata and controls
53 lines (41 loc) · 1.38 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
"""
Word Scramble Generator API - Basic Usage Example
This example demonstrates the basic usage of the Word Scramble Generator API.
API Documentation: https://docs.apiverve.com/ref/wordscramble
"""
import os
import requests
import json
API_KEY = os.getenv('APIVERVE_API_KEY', 'YOUR_API_KEY_HERE')
API_URL = 'https://api.apiverve.com/v1/wordscramble'
def call_wordscramble_api():
"""
Make a GET request to the Word Scramble Generator API
"""
try:
headers = {
'x-api-key': API_KEY
}
response = requests.get(API_URL, headers=headers)
# Raise exception for HTTP errors
response.raise_for_status()
data = response.json()
# Check API response status
if data.get('status') == 'ok':
print('✓ Success!')
print('Response data:', json.dumps(data['data'], indent=2))
return data['data']
else:
print('✗ API Error:', data.get('error', 'Unknown error'))
return None
except requests.exceptions.RequestException as e:
print(f'✗ Request failed: {e}')
return None
if __name__ == '__main__':
print('📤 Calling Word Scramble Generator API...\n')
result = call_wordscramble_api()
if result:
print('\n📊 Final Result:')
print(json.dumps(result, indent=2))
else:
print('\n✗ API call failed')