(false, usrdata)
Check the cloudflare zone record for entries to remove
Check the cloudflare zone record for entries to remove
Check the cloudflare zone record for entries to remove
def checkZone(false, usrdata):
    """ Check the cloudflare zone record for entries to remove """
    # Call api
    request = [('a', 'rec_load_all')]
    json_data = callAPI(request, usrdata)

    # Dicts and Lists for later
    falserecs = {}
    names = {}
    recs = []
    falsedata = {}
    recdata = {}

    # Parse the response and tally false entries
    # Check if the json request is successful
    if json_data["result"] == "success":
        # each zone is a dict in objs dict
        for line in json_data["response"]["recs"]["objs"]:
            # Added this to avoid duplicate zone names (i.e. MX records)
            # example key is A-somedomain.com
            key = line["type"] + "-" + line["name"]
            try:
                names[key] = names[key] + 1
            except KeyError:
                names[key] = 1

            if line["content"] == false:
                falserecs[line["rec_id"]] = key
                falsedata[line["rec_id"]] = {'type': line["type"],
                                              'name': line["name"],
                                              'content': line["content"],
                                              'service_mode': line["service_mode"],
                                              'ttl': line["ttl"],
                                              'prio': line["prio"]}

        # Go through false records
        for rec in falserecs.keys():
            if names[falserecs[rec]] > 1:
                # if record isn't the last entry add for removal
                recs.append(rec)
                recdata[rec] = falsedata[rec]

        # Return the records that have false
        return recs, recdata
def checkZone ( false , usrdata ) : # Call api request = [ ( 'a' , 'rec_load_all' ) ] json_data = callAPI ( request , usrdata ) # Dicts and Lists for later falserecs = { } names = { } recs = [ ] falsedata = { } recdata = { } # Parse the response and tally false entries # Check if the json request is successful if json_data [ "result" ] == "success" : # each zone is a dict in objs dict for line in json_data [ "response" ] [ "recs" ] [ "objs" ] : # Added this to avoid duplicate zone names (i.e. MX records) # example key is A-somedomain.com key = line [ "type" ] + "-" + line [ "name" ] try : names [ key ] = names [ key ] + 1 except KeyError : names [ key ] = 1 if line [ "content" ] == false : falserecs [ line [ "rec_id" ] ] = key falsedata [ line [ "rec_id" ] ] = { 'type' : line [ "type" ] , 'name' : line [ "name" ] , 'content' : line [ "content" ] , 'service_mode' : line [ "service_mode" ] , 'ttl' : line [ "ttl" ] , 'prio' : line [ "prio" ] } # Go through false records for rec in falserecs . keys ( ) : if names [ falserecs [ rec ] ] > 1 : # if record isn't the last entry add for removal recs . append ( rec ) recdata [ rec ] = falsedata [ rec ] # Return the records that have false return recs , recdata