def get_adgroups( modeladmin, request, queryset ): ai = Adwords_interactor() for temp_campaign in queryset: adgroups_of_campaign = ai.get_ad_groups( campaign_id = temp_campaign.id ) for temp_adgroup in adgroups_of_campaign: try: Adgroup.objects.get( id = temp_adgroup['id'] ) except Adgroup.DoesNotExist: ag = Adgroup( campaign = temp_campaign, campaign_id = temp_adgroup['id'], name = temp_adgroup['name'], status = temp_adgroup['status'], stats = temp_adgroup['stats'] ) ag.save()
def get_keywords(modeladmin, request, queryset): ai = Adwords_interactor() for temp_adgroup in queryset: adgroup_keywords = ai.get_ad_group_keywords( ad_group_id = temp_adgroup.id ) for temp_keyword in adgroup_keywords: try: Keyword.objects.get(id=temp_keyword['criterion']['id']) except Keyword.DoesNotExist: kw = Keyword( adgroup = temp_adgroup, id = temp_keyword['criterion']['id'], text = temp_keyword['criterion']['text'], type = temp_keyword['criterion']['type'], match_type = temp_keyword['criterion']['matchType'], stats = temp_keyword.get('stats',0), adgroupcriterion_type = temp_keyword['AdGroupCriterion_Type'], criterion_use = temp_keyword['criterionUse'], criterion_type = temp_keyword['criterion']['type'], ) kw.save()