upload_metrics.py 923 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env vpython3
  2. # Copyright (c) 2018 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import http
  6. import sys
  7. import urllib.error
  8. import urllib.request
  9. import auth
  10. import metrics_utils
  11. def main():
  12. metrics = input()
  13. try:
  14. headers = {}
  15. if 'bot_metrics' in metrics:
  16. token = auth.Authenticator().get_access_token().token
  17. headers = {'Authorization': 'Bearer ' + token}
  18. urllib.request.urlopen(
  19. urllib.request.Request(url=metrics_utils.APP_URL + '/upload',
  20. data=metrics.encode('utf-8'),
  21. headers=headers))
  22. except (urllib.error.HTTPError, urllib.error.URLError,
  23. http.client.RemoteDisconnected):
  24. pass
  25. return 0
  26. if __name__ == '__main__':
  27. sys.exit(main())