(git_url_titles_preemptions)
| 494 | clone_or_pull_git_repository(url) |
| 495 | |
| 496 | def process_git_stats(git_url_titles_preemptions): |
| 497 | GITHUB_STATS_CACHE_FILENAME = 'github-stats-cache.json' |
| 498 | GITHUB_STATS_FILENAME = 'github-stats.json' |
| 499 | |
| 500 | github_stats = {} |
| 501 | try: |
| 502 | with open(GITHUB_STATS_CACHE_FILENAME, 'r', encoding='utf-8') as file: |
| 503 | github_stats = json.load(file) |
| 504 | except FileNotFoundError: |
| 505 | pass |
| 506 | |
| 507 | def is_rate_limit_exceeded(): |
| 508 | return g.rate_limiting[0] <= 20 |
| 509 | |
| 510 | if is_rate_limit_exceeded(): |
| 511 | print(f"GitHub API Rate Limit Exceeded: remained - {(g.rate_limiting_resettime - datetime.datetime.now().timestamp())/60:.2f} min") |
| 512 | else: |
| 513 | def renew_stat(url): |
| 514 | if is_rate_limit_exceeded(): |
| 515 | return |
| 516 | |
| 517 | if 'github.com' not in url: |
| 518 | return None |
| 519 | |
| 520 | print('.', end="") |
| 521 | sys.stdout.flush() |
| 522 | try: |
| 523 | # Parsing the URL |
| 524 | parsed_url = urlparse(url) |
| 525 | domain = parsed_url.netloc |
| 526 | path = parsed_url.path |
| 527 | path_parts = path.strip("/").split("/") |
| 528 | if len(path_parts) >= 2 and domain == "github.com": |
| 529 | owner_repo = "/".join(path_parts[-2:]) |
| 530 | repo = g.get_repo(owner_repo) |
| 531 | owner = repo.owner |
| 532 | now = datetime.datetime.now(datetime.timezone.utc) |
| 533 | author_time_diff = now - owner.created_at |
| 534 | |
| 535 | last_update = repo.pushed_at.strftime("%Y-%m-%d %H:%M:%S") if repo.pushed_at else 'N/A' |
| 536 | item = { |
| 537 | "stars": repo.stargazers_count, |
| 538 | "last_update": last_update, |
| 539 | "cached_time": now.timestamp(), |
| 540 | "author_account_age_days": author_time_diff.days, |
| 541 | } |
| 542 | return url, item |
| 543 | else: |
| 544 | print(f"\nInvalid URL format for GitHub repository: {url}\n") |
| 545 | except Exception as e: |
| 546 | print(f"\nERROR on {url}\n{e}") |
| 547 | |
| 548 | return None |
| 549 | |
| 550 | # resolve unresolved urls |
| 551 | with concurrent.futures.ThreadPoolExecutor(11) as executor: |
| 552 | futures = [] |
| 553 | for url, title, preemptions, node_pattern in git_url_titles_preemptions: |
no test coverage detected