Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for helper function. #16

Open
jerlich opened this issue Sep 7, 2020 · 1 comment
Open

Suggestion for helper function. #16

jerlich opened this issue Sep 7, 2020 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@jerlich
Copy link

jerlich commented Sep 7, 2020

This is a great library. Thanks!

I wrote this function which i find useful, thought others might too:
if you are doing a lot of additions/updates it is better to generate exist first and pass it in rather than have each call get the existing records.

def add_or_update(domain, ip, value, record_type='A', exist=None):

    if not exist:
        exist = client.get_records(domain, record_type=record_type)
    names = [x['name'] for x in exist]
    if value in names:
        if exist[names.index(value)]['data'] != ip:
            client.update_record_ip(ip, domain,value,record_type)
            print(f'Updated {value}.{domain} to point to {ip}.')

        else:
            print(f'{value}.{domain} already points to {ip}. Not changing anything.')
    else:
        client.add_record(domain,
              {
                  'data': ip,
                  'name': value,
                  'ttl':3600,
                  'type':record_type
               })
        print(f'Added record for {value}.{domain} to point to {ip}.')
@eXamadeus
Copy link
Owner

Thanks, yeah that's not a bad idea.

The API isn't the cleanest for GoDaddy to be honest. But at least it is stable, haha. If I get some free time soon, I'm looking at polishing up this library and adding quite a few things I've been collecting.

I'll check this out when I do.

@eXamadeus eXamadeus added the enhancement New feature or request label Jan 6, 2021
@eXamadeus eXamadeus modified the milestones: 2.2.7, 3.x, 3.0 Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants