Repository navigation
Expand file tree
/
Copy pathbasic.py
More file actions
60 lines (47 loc) · 1.8 KB
/
Copy pathbasic.py
File metadata and controls
60 lines (47 loc) · 1.8 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
"""
Parts Of Speech API - Basic Usage Example
This example demonstrates the basic usage of the Parts Of Speech API.
API Documentation: https://docs.apiverve.com/ref/partsofspeech
"""
import os
import requests
import json
API_KEY = os.getenv('APIVERVE_API_KEY', 'YOUR_API_KEY_HERE')
API_URL = 'https://api.apiverve.com/v1/partsofspeech'
def call_partsofspeech_api():
"""
Make a POST request to the Parts Of Speech API
"""
try:
# Request body
request_body = {
'text': 'My friend from college hails from a small countryside village located at the heart of the state. During the last summer vacation, I had an opportunity to visit my friend in his village. I packed up my belongings and boarded the bus bound for the village',
'partofspeech': 'verbs'
}
headers = {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
}
response = requests.post(API_URL, headers=headers, json=request_body)
# 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 Parts Of Speech API...\n')
result = call_partsofspeech_api()
if result:
print('\n📊 Final Result:')
print(json.dumps(result, indent=2))
else:
print('\n✗ API call failed')