Repository navigation
Expand file tree
/
Copy pathbasic.py
More file actions
56 lines (43 loc) · 1.5 KB
/
Copy pathbasic.py
File metadata and controls
56 lines (43 loc) · 1.5 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
"""
Cryptogram Generator API - Basic Usage Example
This example demonstrates the basic usage of the Cryptogram Generator API.
API Documentation: https://docs.apiverve.com/ref/cryptogram
"""
import os
import requests
import json
API_KEY = os.getenv('APIVERVE_API_KEY', 'YOUR_API_KEY_HERE')
API_URL = 'https://api.apiverve.com/v1/cryptogram'
def call_cryptogram_api():
"""
Make a GET request to the Cryptogram Generator API
"""
try:
# Query parameters
params = {'text': 'The quick brown fox', 'random': true}
headers = {
'x-api-key': API_KEY
}
response = requests.get(API_URL, headers=headers, params=params)
# 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 Cryptogram Generator API...\n')
result = call_cryptogram_api()
if result:
print('\n📊 Final Result:')
print(json.dumps(result, indent=2))
else:
print('\n✗ API call failed')