I am using the adwords python api. I need to get the bid amount and type. E.g. bid=4 ad type = cpc.
I am given the adgroup id.
Below is an example on to create and ad group. Once created...how do I retrieve the settings? How do I get e.g. the bid I set?
ad_group_service = client.GetService('AdGroupService', version='v201402')
operations = [{
'operator': 'ADD',
'operand': {
'campaignId': campaign_id,
'name': 'Earth to Mars Cruises #%s' % uuid.uuid4(),
'status': 'ENABLED',
'biddingStrategyConfiguration': {
'bids': [
{
'xsi_type': 'CpcBid',
'bid': {
'microAmount': '1000000'
},
}
]
}
}
}]
ad_groups = ad_group_service.mutate(operations)
Have a look at the corresponding example on googlads's github page.
Basically you'll user the AdGroupService's get method with a selector containing the right fields and predicates to retrieve an AdGroupPage containing the AdGroup objects you're interested in:
selector = {
'fields': ['Id', 'Name', 'CpcBid'],
'predicates': [
{
'field': 'Id',
'operator': 'EQUALS',
'values': [given_adgroup_id]
}
]
}
page = adgroup_service.get(selector)
adgroup = page.entries[0]
print('Adgroup "%s" (%s) has CPC %s' % (adgroup.name, adgroup.id,
adgroup.biddingStrategyConfiguration.bids.bid))
The available fields' names and the attributes they populate in the returned objects can be found at the selector reference page.
The AdGroupService's reference page might also be of interest.
Related
i am looking for a way to search for specific fields in a document using marqo because whenever i use the .search() method the _highlights returns a random field either the title, description or any other field but it is usually random.
this is an example of what i mean:
{
'hits': [
{
'Title': 'document_title',
'Description': 'document_description',
'_highlights': {
'Description': 'document_description'
},
'_id': 'document_id',
'_score': document_score
},
{
'Title': 'document_title',
'Description': "document_description",
'_highlights': {'Title': 'document_title'},
'_id': 'document_id',
'_score': document_score
}
],
'limit': 10,
'processingTimeMs': 49,
'query': 'search_query'
}
as you can see the first documents _highlights is Description while the second is title i want a way to make it uniform.
Thanks!
i think the best way of getting specific fields when using marqo is by add a keyword argument to the search method which is searchable_attributes=[] then you pass the fields you want to list as a string.
eg.
result = mq.index("your_index").search('query', searchable_attributes=['Title', 'Description'])
Hi I am trying to generate a table that will have all the taxi trips of 1 day.
One of the attributes of 1 taxi trip would include a list of all the discounts that that were used on that trip.
There can be any number of discounts used. What I am not sure how to do is how can I include that list of discounts into one item attribute? So basically write 1 item with a list of attributes into DynamoDB?
Here is my table:
def create_table(self):
table = dynamodb.create_table(
TableName='TaxiTable',
KeySchema=[
{
'AttributeName': 'trip',
'KeyType': 'HASH'
},
],
AttributeDefinitions=[
{
'AttributeName': 'trip',
'AttributeType': 'S'
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 10
}
)
print("Table status:", table.table_status)
The 'trip' key would be 1 long string with the origin of that taxi ride, where it's last stop of the day was at, the taxi number, the number of stops, and the date of the trip.
trip_key: 12thAve.MapleDrive.0124.02.02202020
underneath as an attribute I would like a list of all the discounts that were used on that taxi trip/
Something like:
trip_key: 12thAve.MapleDrive.0124.02.02202020
discount_map:
{
discount1: { name: 'Senior', total_saved: '10'},
discount2: { name: 'Student', total_saved: '30'},
discount3: { name: 'Employee', total_saved: '20'},
discount4: { name: 'Hotel', total_saved: '30'}
}
I do not know how many discounts could be used on one trip. Could be between 5-10. But I would like to include all the discounts used in one insert. I would want to query a specific discount used on a taxi trip and the total saved from this table.
I dont know if first I should convert the list into a JSON object? Or if there is a way to iterate through the list and insert it how I would like.
import boto3
class taxi_discount:
name = None
total_saved = None
# rest of logic for this class...
class insert_to_dynamoDb:
dynamodb = boto3.resource('dynamodb', region_name='us-west-2', endpoint_url="http://localhost:8000")
taxi_trip_key= None
taxi_discounts_list = []
def __init__(taxi_trip, discount_list):
self.taxi_trip_key= taxi_trip
self.discount_list = discount_list
def write_to_table(self):
table = dynamodb.Table('TaxiTable')
response = table.put_item(
Item={
'trip': taxi_trip_key,
'discount_map': taxi_discounts_list
}
} )
DynamoDB supports batch writing.
Example from docs:
with table.batch_writer() as batch:
for i in range(50):
batch.put_item(
Item={
'account_type': 'anonymous',
'username': 'user' + str(i),
'first_name': 'unknown',
'last_name': 'unknown'
}
)
Guide docs
API docs
I was trying to change the keyword status via Google Ads API the following code shows how to update the keyword bid... however, I was looking for a way to set the keyword status as paused, I haven't been able to find any info within the documentation to paused the keyword
from googleads import adwords
AD_GROUP_ID = 'INSERT_AD_GROUP_ID_HERE'
CRITERION_ID = 'INSERT_KEYWORD_CRITERION_ID_HERE'
def main(client, ad_group_id, criterion_id):
# Initialize appropriate service.
ad_group_criterion_service = client.GetService(
'AdGroupCriterionService', version='v201809')
# Construct operations and update bids.
operations = [{
'operator': 'SET',
'operand': {
'xsi_type': 'BiddableAdGroupCriterion',
'adGroupId': ad_group_id,
'criterion': {
'id': criterion_id,
},
'biddingStrategyConfiguration': {
'bids': [
{
'xsi_type': 'CpcBid',
'bid': {
'microAmount': '1000000'
}
}
]
}
}
}]
ad_group_criteria = ad_group_criterion_service.mutate(operations)
# Display results.
if 'value' in ad_group_criteria:
for criterion in ad_group_criteria['value']:
if criterion['criterion']['Criterion.Type'] == 'Keyword':
print('Ad group criterion with ad group id "%s" and criterion id '
'"%s" currently has bids:'
% (criterion['adGroupId'], criterion['criterion']['id']))
for bid in criterion['biddingStrategyConfiguration']['bids']:
print('\tType: "%s", value: %s' % (bid['Bids.Type'],)
bid['bid']['microAmount'])
else:
print('No ad group criteria were updated.')
if __name__ == '__main__':
# Initialize client object.
adwords_client = adwords.AdWordsClient.LoadFromStorage()
main(adwords_client, AD_GROUP_ID, CRITERION_ID)
Thanks in advance for the help...
After more research I found the following guide.
https://developers.google.com/adwords/api/docs/reference/v201809/AdGroupCriterionService.BiddableAdGroupCriterion#userstatus
In order to modified the keyword status the construct operations needs to be like this.
operations = [{
'operator': 'SET',
'operand': {
'xsi_type': 'BiddableAdGroupCriterion',
'adGroupId': ad_group_id,
'criterion': {
'id': criterion_id,
},
'userStatus': 'ENABLED'
}
}]
I'm trying to fetch the audiences (Custom intent, Custom affinity) of all my enabled google display campaigns.
I thought I can get it through the CampaignCriterionService, but the returned data is empty.
campaign_criterion_service = ADWORDS_CLIENT.GetService(
'CampaignCriterionService', version='v201809')
selector = {
'fields': ['CampaignId', 'Id', 'CriteriaType', "PlacementUrl",
'KeywordText', "ChannelName", "AppId", "DisplayName", "CampaignStatus", "CampaignName"],
'predicates': [{
'field': 'CriteriaType',
'operator': 'IN',
'values': [
'CUSTOM_AFFINITY',
'CUSTOM_INTENT'
]
},
{
'field': 'CampaignStatus',
'operator': 'IN',
'values': [
'ENABLED'
]
}
],
'paging': {
'startIndex': 0,
'numberResults': 500
}
}
page = campaign_criterion_service.get(selector)
Any clues?
You are searching for ways to to report your results, read about reporting with google adwords. The recommended way of using this with the python lib is described Here.
I am having trouble updating document in MongoDB that involves adding to list and updating some fields, using Pymongo.
To summarize, I would like to:
Add a value to the a list.
Update some fields.
Using a single update statement.
I have tried 2 methods, but both doesn't work:
key = {'username':'user1'}
user_detail = {
'name':{'first':'Marie', 'last':'Bender'},
'items':{'$addtoset':{'cars':'BMW'}}
}
user_detail2 = {
'name':{'first':'Marie', 'last':'Bender'},
'$addtoset':{'items.cars':'BMW'}
}
mongo_collection.update(key, user_detail, upsert=True)
mongo_collection.update(key, user_detail2, upsert=True)
error message: dollar ($) prefixed field '$addToSet' in '$addToSet' is not valid for storage.
My intended outcome:
Before:
{
'username':'user1',
'item': {'cars':['Merc','Ferrari'],'house':1}
}
Intended After:
{
'username':'user1',
'name': {'first':'Marie', 'last':'Bender'},
'item': {'cars':['Merc','Ferrari','BMW'],'house':1}
}
Your second attempt is closer, but you need to use the $set operator to set the value of name:
user_detail2 = {
'$set': {'name': {'first': 'Marie', 'last': 'Bender'}},
'$addtoset': {'items.cars': 'BMW'}
}