File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 671671
672672The ** jq -r** option is used to convert newlines and tabs within the JSON response data. The egrep is used for documentation brevity.
673673
674+ This can also be done via Python code with the following example.
675+ ```
676+ #!/usr/bin/env python
677+ import sys
678+ import CloudFlare
679+
680+ def main():
681+ zone_name = sys.argv[1]
682+ cf = CloudFlare.CloudFlare()
683+
684+ zones = cf.zones.get(params={'name': zone_name})
685+ zone_id = zones[0]['id']
686+
687+ dns_records = cf.zones.dns_records.export.get(zone_id)
688+ for l in dns_records.splitlines():
689+ if len(l) == 0 or l[0] == ';':
690+ continue
691+ print l
692+ exit(0)
693+
694+ if __name__ == '__main__':
695+ main()
696+ ```
697+
674698## Implemented API calls
675699
676700The ** --dump** argument to cli4 will produce a list of all the call implemented within the library.
Original file line number Diff line number Diff line change @@ -739,6 +739,31 @@ page within the Cloudflare portal.
739739The **jq -r ** option is used to convert newlines and tabs within the
740740JSON response data. The egrep is used for documentation brevity.
741741
742+ This can also be done via Python code with the following example.
743+
744+ ::
745+
746+ #!/usr/bin/env python
747+ import sys
748+ import CloudFlare
749+
750+ def main():
751+ zone_name = sys.argv[1]
752+ cf = CloudFlare.CloudFlare()
753+
754+ zones = cf.zones.get(params={'name': zone_name})
755+ zone_id = zones[0]['id']
756+
757+ dns_records = cf.zones.dns_records.export.get(zone_id)
758+ for l in dns_records.splitlines():
759+ if len(l) == 0 or l[0] == ';':
760+ continue
761+ print l
762+ exit(0)
763+
764+ if __name__ == '__main__':
765+ main()
766+
742767Implemented API calls
743768---------------------
744769
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+ sys .path .insert (0 , os .path .abspath ('..' ))
7+
8+ import CloudFlare
9+
10+ def main ():
11+ """Cloudflare API code - example"""
12+
13+ try :
14+ zone_name = sys .argv [1 ]
15+ except IndexError :
16+ exit ('usage: example_dns_export.py zone' )
17+
18+ cf = CloudFlare .CloudFlare ()
19+
20+ # grab the zone identifier
21+ try :
22+ params = {'name' : zone_name }
23+ zones = cf .zones .get (params = params )
24+ except CloudFlare .exceptions .CloudFlareAPIError as e :
25+ exit ('/zones %d %s - api call failed' % (e , e ))
26+ except Exception as e :
27+ exit ('/zones.get - %s - api call failed' % (e ))
28+
29+ if len (zones ) == 0 :
30+ exit ('/zones.get - %s - zone not found' % (zone_name ))
31+
32+ if len (zones ) != 1 :
33+ exit ('/zones.get - %s - api call returned %d items' % (zone_name , len (zones )))
34+
35+ zone_id = zones [0 ]['id' ]
36+
37+ try :
38+ dns_records = cf .zones .dns_records .export .get (zone_id )
39+ except CloudFlare .exceptions .CloudFlareAPIError as e :
40+ exit ('/zones/dns_records/export %s - %d %s - api call failed' % (dns_name , e , e ))
41+
42+ for l in dns_records .splitlines ():
43+ if len (l ) == 0 or l [0 ] == ';' :
44+ # blank line or comment line are skipped - to make example easy to see
45+ continue
46+ print l
47+
48+ exit (0 )
49+
50+ if __name__ == '__main__' :
51+ main ()
52+
You can’t perform that action at this time.
0 commit comments