Skip to content

Commit

Permalink
added with statement example
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Oct 9, 2017
1 parent 5c4a872 commit 97cd013
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/example_with_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
"""Cloudflare API code - example"""

import os
import sys

sys.path.insert(0, os.path.abspath('..'))
import CloudFlare

def main():
"""Cloudflare API code - example"""

# Grab the first argument, if there is one
try:
zone_name = sys.argv[1]
params = {'name':zone_name, 'per_page':1}
except IndexError:
params = {'per_page':50}

#
# Show how 'with' statement works
#
with CloudFlare.CloudFlare() as cf:
zones = cf.zones(params=params)
for zone in sorted(zones, key=lambda v: v['name']):
print zone['id'], zone['name']

exit(0)

if __name__ == '__main__':
main()

0 comments on commit 97cd013

Please sign in to comment.