def _get_config(): config = Config() # load default config config.loadFromFile(Config.DEFAULT_CONFIG_FILE) # to load directly from apikey instead, use # config.createFromAPIKey('qACMD09OJXBxT7XOuRs8') return config
# # Copyright (c) 2014 NSONE, Inc. # # License under The MIT License (MIT). See LICENSE in project root. # ########### # TWISTED # ########### from ns1 import NS1, Config from twisted.internet import defer, reactor config = Config() # load default config config.loadFromFile(Config.DEFAULT_CONFIG_FILE) # to load directly from apikey instead, use # config.createFromAPIKey('qACMD09OJXBxT7XOuRs8') # override default synchronous transport. note, this would normally go # in config file. config["transport"] = "twisted" api = NS1(config=config) @defer.inlineCallbacks def getQPS(): # when twisted transport is in use, all of the NS1 methods return # Deferred. yield them to gather the results, or add callbacks/errbacks # to be run when results are available zone = yield api.loadZone("test.com")
''' dns-importer: read in csv file and upload ''' import csv import os import sys from ns1 import NS1, Config from twisted.internet import defer, reactor # Increase timeout if too many twisted ConnectionLost REACTOR_TIMEOUT = 5 # load default config from ~/.nsone (see nsone.sample) config = Config() config.loadFromFile(Config.DEFAULT_CONFIG_FILE) ''' # OR generate default with api key AND adjust config config.createFromAPIKey('AbCdEfGhiJKlMnOpQrSt') config['transport'] = 'twisted' config['verbosity'] = 5 ''' api = NS1(config=config) def fix_data(r): ''' fix_data is used to reshape the data according to the type ''' if r['Type'] == 'MX': data = r['Data'].split(' ') return [[ int(data[0]), ' '.join(data[1:]) ]]