upload_metrics.py 834 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 os
  7. import sys
  8. import urllib.error
  9. import urllib.request
  10. import auth
  11. import metrics_utils
  12. def main():
  13. metrics = input()
  14. try:
  15. headers = {}
  16. if 'bot_metrics' in metrics:
  17. token = auth.Authenticator().get_access_token().token
  18. headers = {'Authorization': 'Bearer ' + token}
  19. urllib.request.urlopen(urllib.request.Request(
  20. url=metrics_utils.APP_URL + '/upload',
  21. data=metrics.encode('utf-8'),
  22. headers=headers))
  23. except (urllib.error.HTTPError, urllib.error.URLError,
  24. http.client.RemoteDisconnected):
  25. pass
  26. return 0
  27. if __name__ == '__main__':
  28. sys.exit(main())