

'''simple docstring'''







import argparse
import math
import traceback

import dateutil.parser as date_parser
import requests
def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			Tuple:
       A_						=      {}

       A_						=      job["""started_at"""]
       A_						=      job["""completed_at"""]

       A_						=      date_parser.parse(lowercase_				)
       A_						=      date_parser.parse(lowercase_				)

       A_						=      round((end_datetime - start_datetime).total_seconds() / 60.0				)

       A_						=      start
       A_						=      end
       A_						=      duration_in_min

       return job_info
def       UpperCAmelCase__    (      UpperCAmelCase__,       UpperCAmelCase__=None				)			->			Tuple:
       A_						=      None
       if token is not None:
              A_						=      {"""Accept""": """application/vnd.github+json""", """Authorization""": F'''Bearer {token}'''}

       A_						=      F'''https://api.github.com/repos/huggingface/transformers/actions/runs/{workflow_run_id}/jobs?per_page=100'''
       A_						=      requests.get(lowercase_,       headers=lowercase_				).json()
       A_						=      {}

       try:
              job_time.update({job["""name"""]: extract_time_from_single_job(lowercase_				) for job in result["""jobs"""]}				)
              A_						=      math.ceil((result["""total_count"""] - 1_00) / 1_00				)

              for i in range(lowercase_				):
                     A_						=      requests.get(url + F'''&page={i + 2}''',       headers=lowercase_				).json()
                     job_time.update({job["""name"""]: extract_time_from_single_job(lowercase_				) for job in result["""jobs"""]}				)

              return job_time
       except Exception:
              print(F'''Unknown error, could not fetch links:\n{traceback.format_exc()}'''				)

       return {}


if __name__ == "__main__":
      __lowerCamelCase		       =    argparse.ArgumentParser()
      # Required parameters
      parser.add_argument('''--workflow_run_id''', type=str, required=True, help='''A GitHub Actions workflow run id.''')
      __lowerCamelCase		       =    parser.parse_args()

      __lowerCamelCase		       =    get_job_time(args.workflow_run_id)
      __lowerCamelCase		       =    dict(sorted(job_time.items(), key=lambda item: item[1]["duration"], reverse=True))

      for k, v in job_time.items():
            print(f"""{k}: {v['duration']}""")



'''simple docstring'''







def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			bool:
       if num < 0:
              return False

       A_						=      num
       A_						=      0
       while num > 0:
              A_						=      rev_num * 10 + (num % 10)
              num //= 10

       return num_copy == rev_num


if __name__ == "__main__":
      import doctest

      doctest.testmod()
