• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2#
3# Copyright 2014 Google Inc. All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""Gets all alerts available for the logged in user's account.
18
19Tags: alerts.list
20"""
21from __future__ import print_function
22
23__author__ = 'sgomes@google.com (Sérgio Gomes)'
24
25import argparse
26import sys
27
28from googleapiclient import sample_tools
29from oauth2client import client
30
31
32def main(argv):
33  # Authenticate and construct service.
34  service, flags = sample_tools.init(
35      argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[],
36      scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
37
38  try:
39    # Retrieve alerts list in pages and display data as we receive it.
40    request = service.alerts().list()
41
42    if request is not None:
43      result = request.execute()
44      if 'items' in result:
45        alerts = result['items']
46        for alert in alerts:
47          print(('Alert id "%s" with severity "%s" and type "%s" was found. '
48                 % (alert['id'], alert['severity'], alert['type'])))
49      else:
50        print('No alerts found!')
51  except client.AccessTokenRefreshError:
52    print ('The credentials have been revoked or expired, please re-run the '
53           'application to re-authorize')
54
55if __name__ == '__main__':
56  main(sys.argv)
57