This repository was archived by the owner on Nov 22, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ """Cloudflare API code - example"""
3+
4+ import os
5+ import sys
6+ import json
7+ sys .path .insert (0 , os .path .abspath ('..' ))
8+
9+ import CloudFlare
10+
11+ def main ():
12+ """Cloudflare API code - example"""
13+
14+ try :
15+ account_name = sys .argv [1 ]
16+ except IndexError :
17+ exit ('usage: example_page_rules.py account' )
18+
19+ cf = CloudFlare .CloudFlare ()
20+
21+ # grab the account identifier
22+ try :
23+ params = {'name' : account_name }
24+ accounts = cf .accounts .get (params = params )
25+ except CloudFlare .exceptions .CloudFlareAPIError as e :
26+ exit ('/accounts %d %s - api call failed' % (e , e ))
27+ except Exception as e :
28+ exit ('/accounts.get - %s - api call failed' % (e ))
29+
30+ if len (accounts ) == 0 :
31+ exit ('/accounts.get - %s - account not found' % (account_name ))
32+
33+ if len (accounts ) != 1 :
34+ exit ('/accounts.get - %s - api call returned %d items' % (account_name , len (accounts )))
35+
36+ account_id = accounts [0 ]['id' ]
37+
38+ r = cf .accounts .email_fwdr .addresses .get (account_id )
39+
40+ print (json .dumps (r , indent = 4 ))
41+
42+ exit (0 )
43+
44+ if __name__ == '__main__' :
45+ main ()
You can’t perform that action at this time.
0 commit comments