Skip to content

Commit

Permalink
Committing latest changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
grivescorbett committed Apr 6, 2018
1 parent b93ae8e commit aeb1176
Show file tree
Hide file tree
Showing 22 changed files with 4,276 additions and 8 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
11.0.1 -- 04/06/18
* Fixed bug related to creating types from services that
contain multiple schemas.
* Fixed bug in README.md related to zeep caching.

11.0.0 -- 03/21/18
* Removed support and examples for AdWords v201705, and v201708.
* The default SOAP backend is now zeep. If you encounter any issues,
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ You can also disable caching in similar fashion with zeep
```python
adwords_client = adwords.AdWordsClient(
developer_token, oauth2_client, user_agent,
client_customer_id=client_customer_id, cache=None)
client_customer_id=client_customer_id,
cache=googleads.common.ZeepServiceProxy.NO_CACHE)
```

And with suds:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ def DisplayEstimate(message, min_estimate, max_estimate):
# Find the mean of the min and max values.
mean_avg_cpc = (_CalculateMean(min_estimate['averageCpc']['microAmount'],
max_estimate['averageCpc']['microAmount'])
if 'averageCpc' in min_estimate else None)
if 'averageCpc' in min_estimate
and min_estimate['averageCpc'] else None)
mean_avg_pos = (_CalculateMean(min_estimate['averagePosition'],
max_estimate['averagePosition'])
if 'averagePosition' in min_estimate else None)
if 'averagePosition' in min_estimate
and min_estimate['averagePosition'] else None)
mean_clicks = _CalculateMean(min_estimate['clicksPerDay'],
max_estimate['clicksPerDay'])
mean_total_cost = _CalculateMean(min_estimate['totalCost']['microAmount'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ def DisplayEstimate(message, min_estimate, max_estimate):
# Find the mean of the min and max values.
mean_avg_cpc = (_CalculateMean(min_estimate['averageCpc']['microAmount'],
max_estimate['averageCpc']['microAmount'])
if 'averageCpc' in min_estimate else None)
if 'averageCpc' in min_estimate
and min_estimate['averageCpc'] else None)
mean_avg_pos = (_CalculateMean(min_estimate['averagePosition'],
max_estimate['averagePosition'])
if 'averagePosition' in min_estimate else None)
if 'averagePosition' in min_estimate
and min_estimate['averagePosition'] else None)
mean_clicks = _CalculateMean(min_estimate['clicksPerDay'],
max_estimate['clicksPerDay'])
mean_total_cost = _CalculateMean(min_estimate['totalCost']['microAmount'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python
#
# Copyright 2018 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This code example activates paused live stream events."""

# Import appropriate modules from the client library.
from googleads import dfp

# Set the id of the LiveStreamEvent to get live stream events from.
LIVE_STREAM_EVENT_ID = 'INSERT_LIVE_STREAM_EVENT_ID_HERE'


def main(client, live_stream_event_id):
# Initialize appropriate service.
live_stream_event_service = client.GetService(
'LiveStreamEventService', version='v201708')

# Create query to find paused live stream events.
statement = (dfp.StatementBuilder()
.Where(('id = :id AND '
'status = :status'))
.WithBindVariable('status', 'PAUSED')
.WithBindVariable('id', long(live_stream_event_id))
.Limit(500))

live_stream_events_activated = 0

# Get live stream events by statement.
while True:
response = live_stream_event_service.getLiveStreamEventsByStatement(
statement.ToStatement())
if 'results' in response:
for live_stream_event in response['results']:
print('live stream event with id "%s" and name "%s" will be activated.'
% (live_stream_event['id'], live_stream_event['name']))

# Perform action.
result = live_stream_event_service.performLiveStreamEventAction({
'xsi_type': 'ActivateLiveStreamEvents'
}, statement.ToStatement())
if result and int(result['numChanges']) > 0:
live_stream_events_activated += int(result['numChanges'])
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break

# Display results.
if live_stream_events_activated > 0:
print '# of live stream events activated: %s' % (
live_stream_events_activated)
else:
print 'No live stream events were activated.'


if __name__ == '__main__':
# Initialize client object.
dfp_client = dfp.DfpClient.LoadFromStorage()
main(dfp_client, LIVE_STREAM_EVENT_ID)
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python
#
# Copyright 2018 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This code example creates new live stream events.
To determine which live stream events exist, run get_all_live_stream_events.py.
To determine which cdn configurations exist, run get_cdn_configurations.py.
"""

import datetime
import uuid

# Import appropriate modules from the client library.
from googleads import dfp
import pytz

# Set content urls and adTags to use
CONTENT_URLS = ['INSERT_CONTENT_URLS_HERE']
AD_TAGS = ['INSERT_AD_TAGS_HERE']


def main(client, content_urls, ad_tags):
# Initialize appropriate services.
live_events_service = client.GetService(
'LiveStreamEventService', version='v201708')

# Stream will play for 365 days
start_datetime = datetime.datetime.now(tz=pytz.timezone('America/New_York'))
end_datetime = start_datetime + datetime.timedelta(days=365)

# Create live stream event objects
live_stream_events = [{
'name': 'Live Stream Event #%s' % uuid.uuid4(),
'startDateTime': start_datetime,
'endDateTime': end_datetime,
'contentUrls': content_urls,
'adTags': ad_tags
}]

# Add live stream events.
live_stream_events = live_events_service.createLiveStreamEvents(
live_stream_events)

# Display results.
for live_stream_event in live_stream_events:
print(
'Live stream event with id "%s", named "%s" and status %s was created.'
% (live_stream_event['id'], live_stream_event['name'],
live_stream_event['status']))


if __name__ == '__main__':
# Initialize client object.
dfp_client = dfp.DfpClient.LoadFromStorage()
main(dfp_client, CONTENT_URLS, AD_TAGS)
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python
#
# Copyright 2018 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This example gets all live stream events.
"""

# Import appropriate modules from the client library.
from googleads import dfp


def main(client):
# Initialize appropriate service.
live_stream_event_service = client.GetService(
'LiveStreamEventService', version='v201708')

# Create a statement to select live stream events.
statement = dfp.StatementBuilder()

# Retrieve a small amount of live stream events at a time, paging
# through until all live stream events have been retrieved.
while True:
response = live_stream_event_service.getLiveStreamEventsByStatement(
statement.ToStatement())
if 'results' in response:
for live_stream_event in response['results']:
# Print out some information for each live stream event.
print('live stream event with id "%d" and name "%s" was found.' %
(live_stream_event['id'], live_stream_event['name']))
statement.offset += statement.limit
else:
break

print '\nNumber of results found: %s' % response['totalResultSetSize']


if __name__ == '__main__':
# Initialize client object.
dfp_client = dfp.DfpClient.LoadFromStorage()
main(dfp_client)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
#
# Copyright 2018 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This example registers all live stream event-sessions ids for monitoring."""

# Import appropriate modules from the client library.
from googleads import dfp

# List of session ids
SESSION_IDS = ['INSERT_SESSION_IDS_HERE']


def main(client, session_ids):
# Initialize appropriate service.
live_stream_event_service = client.GetService(
'LiveStreamEventService', version='v201708')

# Retrieve all sessions id that are being monitored
session_ids = live_stream_event_service.registerSessionsForMonitoring(
session_ids)
if session_ids:
for session_id in session_ids:
# Print out some information for each live stream event.
print 'Session with ID "%s" registered for monitoring.' % (session_id)

print '\nNumber of results found: %s' % session_ids.size


if __name__ == '__main__':
# Initialize client object.
dfp_client = dfp.DfpClient.LoadFromStorage()
main(dfp_client, SESSION_IDS)
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python
#
# Copyright 2018 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This code example updates live stream events.
To determine which live stream events exist, run get_all_live_stream_events.py.
"""

# Import appropriate modules from the client library.
from googleads import dfp

# Set ID of the LiveStreamEvent to get live stream events from.
LIVE_STREAM_EVENT_ID = 'INSERT_LIVE_STREAM_EVENT_ID_HERE'


def main(client, live_stream_event_id):
# Initialize appropriate services.
live_stream_events_service = client.GetService(
'LiveStreamEventService', version='v201708')

# Create statement object to only select matching live stream event.
statement = (dfp.StatementBuilder()
.Where(('Id = :id'))
.WithBindVariable('id', long(live_stream_event_id))
.Limit(500))

# Get live stream events by statement.
response = live_stream_events_service.getLiveStreamEventsByStatement(
statement.ToStatement())

# Set adTags to be updated.
new_ad_tags = ['INSERT_NEW_AD_TAGS_HERE']

if 'results' in response:
# Update each local live stream event by changing its attributes.
updated_live_stream_events = []
for live_stream_event in response['results']:
live_stream_event['startDateTimeType'] = 'IMMEDIATELY'
live_stream_event['adTags'] = new_ad_tags
updated_live_stream_events.append(live_stream_event)

# Update live stream events.
live_stream_events = live_stream_events_service.updateLiveStreamEvents(
updated_live_stream_events)

# Display results.
for live_stream_event in live_stream_events:
print('Live stream event with id "%s", named "%s" and status %s was '
'updated.' % (live_stream_event['id'], live_stream_event['name'],
live_stream_event['status']))


if __name__ == '__main__':
# Initialize client object.
dfp_client = dfp.DfpClient.LoadFromStorage()
main(dfp_client, LIVE_STREAM_EVENT_ID)
Loading

0 comments on commit aeb1176

Please sign in to comment.