def get(self): """Handle get request.""" client_customer_id = self.request.get('clientCustomerId') template_values = { 'back_url': '/showAccounts', 'back_msg': 'View Accounts.', 'ccid': client_customer_id, 'logout_url': users.create_logout_url('/'), 'user_nickname': users.get_current_user().nickname() } try: try: app_user = InitUser() # Load Client instance. handler = APIHandler(app_user.client_id, app_user.client_secret, app_user.refresh_token, app_user.adwords_manager_cid, app_user.developer_token) campaigns = handler.GetCampaigns(client_customer_id) except Exception as e: template_values['error'] = str(e) finally: # Use template to write output to the page. template_values['campaigns'] = campaigns path = os.path.join(os.path.dirname(__file__), '../templates/show_campaigns.html') self.response.out.write(template.render(path, template_values))
def post(self): """Handle post request.""" client_customer_id = self.request.get('clientCustomerId') budget_id = self.request.get('budgetId') micro_amount = self.request.get('microAmount') delivery_method = self.request.get('delivery') template_values = { 'back_url': ('/showBudget?clientCustomerId=%s&budgetId=%s' % (client_customer_id, budget_id)), 'back_msg': 'View Budget', 'logout_url': users.create_logout_url('/'), 'user_nickname': users.get_current_user().nickname() } try: app_user = InitUser() # Load Client instance. handler = APIHandler(app_user.client_id, app_user.client_secret, app_user.refresh_token, app_user.mcc_cid, app_user.developer_token) # Update the Budget. handler.UpdateBudget(client_customer_id, budget_id, micro_amount, delivery_method) self.redirect('/showBudget?clientCustomerId=%s&budgetId=%s' % (client_customer_id, budget_id)) except Exception, e: # Use template to write output to the page. template_values['error'] = str(e) path = os.path.join(os.path.dirname(__file__), '../templates/base_template.html') self.response.out.write(template.render(path, template_values))
def post(self): """Handle post request.""" client_customer_id = self.request.get('clientCustomerId') campaign_name = self.request.get('campaignName') ad_channel_type = self.request.get('adChannelType') budget = self.request.get('budget') template_values = { 'back_url': '/showCampaigns?clientCustomerId=%s' % client_customer_id, 'back_msg': 'View Campaigns', 'logout_url': users.create_logout_url('/'), 'user_nickname': users.get_current_user().nickname() } try: app_user = InitUser() # Load Client instance. handler = APIHandler(app_user.client_id, app_user.client_secret, app_user.refresh_token, app_user.adwords_manager_cid, app_user.developer_token) # Create new campaign. handler.AddCampaign(client_customer_id, campaign_name, ad_channel_type, budget) self.redirect('/showCampaigns?clientCustomerId=%s' % client_customer_id) except Exception, e: template_values['error'] = str(e) # Use template to write output to the page. path = os.path.join(os.path.dirname(__file__), '../templates/base_template.html') self.response.out.write(template.render(path, template_values))
def get(self): """Handle get request.""" template_values = { 'back_url': '/showCredentials', 'back_msg': 'View Credentials', 'logout_url': users.create_logout_url('/'), 'user_nickname': users.get_current_user().nickname() } try: try: app_user = InitUser() # Load Client instance. handler = APIHandler(app_user.client_id, app_user.client_secret, app_user.refresh_token, app_user.mcc_cid, app_user.developer_token, debug=DEBUG) # Fetch account info for each client account and place in template. template_values['accounts'] = handler.GetAccounts() except Exception, e: template_values['error'] = str(e) finally: # Use template to write output to the page. path = os.path.join(os.path.dirname(__file__), '../templates/show_accounts.html') self.response.out.write(template.render(path, template_values))
def get(self): """Handle get request.""" client_customer_id = self.request.get('clientCustomerId') campaign_id = self.request.get('campaignId') template_values = { 'back_url': '/showCampaigns?clientCustomerId=%s' % client_customer_id, 'back_msg': 'View Campaigns.', 'campaign_id': campaign_id, 'ccid': client_customer_id, 'logout_url': users.create_logout_url('/'), 'user_nickname': users.get_current_user().nickname() } try: try: app_user = InitUser() # Load Client instance. handler = APIHandler(app_user.client_id, app_user.client_secret, app_user.refresh_token, app_user.mcc_cid, app_user.developer_token, debug=DEBUG) adgroups = handler.GetAdGroups(client_customer_id, campaign_id) # Use template to write output to the page. template_values['adgroups'] = adgroups except Exception, e: template_values['error'] = str(e) finally: path = os.path.join(os.path.dirname(__file__), '../templates/show_adgroups.html') self.response.out.write(template.render(path, template_values))
def post(self): """Handle post request.""" client_customer_id = self.request.get('clientCustomerId') campaign_id = self.request.get('campaignId') campaign_name = self.request.get('name') campaign_status = self.request.get('status') template_values = { 'back_url': ('/showAdGroups?clientCustomerId=%s&campaignId=%s' % (client_customer_id, campaign_id)), 'back_msg': 'View AdGroups', 'logout_url': users.create_logout_url('/'), 'user_nickname': users.get_current_user().nickname() } try: app_user = InitUser() # Load Client instance. handler = APIHandler(app_user.client_id, app_user.client_secret, app_user.refresh_token, app_user.mcc_cid, app_user.developer_token) # Create new ad group. handler.AddAdGroup(client_customer_id, campaign_id, campaign_name, campaign_status) self.redirect('/showAdGroups?clientCustomerId=%s&campaignId=%s' % (client_customer_id, campaign_id)) except Exception, e: template_values['error'] = str(e) # Use template to write output to the page. path = os.path.join(os.path.dirname(__file__), '../templates/base_template.html') self.response.out.write(template.render(path, template_values))
def get(self): adwords_client = adwords.AdWordsClient.LoadFromStorage( 'googleads.yaml') path = os.path.join(os.path.dirname(__file__), '../googleads.yaml') stream = open(path, 'r') authTokens = yaml.load(stream) client_customer_id = authTokens.get('adwords').get( 'client_customer_id') client_id = authTokens.get('adwords').get('client_id') developer_token = authTokens.get('adwords').get('developer_token') client_secret = authTokens.get('adwords').get('client_secret') data = [] try: try: # Load Client instance. handler = APIHandler(client_id, client_secret, developer_token) campaigns = handler.GetCampaigns(client_customer_id) for campaign in campaigns: data.append(campaign.name) except Exception, e: data.append(str(e)) finally: self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(data))