|
| 1 | +from github import Github |
| 2 | +import os |
| 3 | +import datetime |
| 4 | +import json |
| 5 | +from pathlib import Path |
| 6 | +from src.github_api import GitHubAPI |
| 7 | + |
| 8 | +def update_readme_stats(stats, content): |
| 9 | + stats_section = f"""## 📊 Repository Stats |
| 10 | +- ⭐ Stars: {stats['stars']} |
| 11 | +- 🍴 Forks: {stats['forks']} |
| 12 | +- 📬 Open Issues: {stats['issues']} |
| 13 | +- 👀 Watchers: {stats['watchers']} |
| 14 | +- 📅 Last Updated: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M UTC')} |
| 15 | +""" |
| 16 | + return content.replace("## 📊 Repository Stats\n", stats_section) |
| 17 | + |
| 18 | +def update_trending_section(trending_repos, content): |
| 19 | + trending_section = "### 🔥 Trending Repositories\n" |
| 20 | + for repo in trending_repos[:5]: |
| 21 | + trending_section += f"- [{repo['full_name']}]({repo['html_url']}): {repo['description']} ⭐{repo['stargazers_count']}\n" |
| 22 | + |
| 23 | + return content.replace("### 🔥 Trending Repositories\n", trending_section) |
| 24 | + |
| 25 | +def update_language_section(language_stats, content): |
| 26 | + language_section = "### 🎨 By Programming Language\n" |
| 27 | + for lang, stats in sorted(language_stats.items(), key=lambda x: x[1]['stars'], reverse=True)[:5]: |
| 28 | + language_section += f"- {lang}: {stats['count']} repositories, {stats['stars']} total stars\n" |
| 29 | + |
| 30 | + return content.replace("### 🎨 By Programming Language\n", language_section) |
| 31 | + |
| 32 | +def main(): |
| 33 | + # Initialize API clients |
| 34 | + github_token = os.environ['GITHUB_TOKEN'] |
| 35 | + g = Github(github_token) |
| 36 | + api = GitHubAPI(github_token) |
| 37 | + |
| 38 | + # Get repository stats |
| 39 | + repo = g.get_repo("AasishPokhrel/shit") |
| 40 | + stats = { |
| 41 | + 'stars': repo.stargazers_count, |
| 42 | + 'forks': repo.forks_count, |
| 43 | + 'issues': repo.open_issues_count, |
| 44 | + 'watchers': repo.watchers_count |
| 45 | + } |
| 46 | + |
| 47 | + # Get trending repositories |
| 48 | + trending_repos = api.get_trending_repos(since="weekly") |
| 49 | + |
| 50 | + # Get language statistics |
| 51 | + language_stats = api.get_language_stats() |
| 52 | + |
| 53 | + # Get topic statistics |
| 54 | + topics = ["ai", "web-development", "mobile", "devops", "security"] |
| 55 | + topic_stats = api.get_topic_stats(topics) |
| 56 | + |
| 57 | + # Update README |
| 58 | + with open('README.md', 'r', encoding='utf-8') as file: |
| 59 | + content = file.read() |
| 60 | + |
| 61 | + content = update_readme_stats(stats, content) |
| 62 | + content = update_trending_section(trending_repos.get('items', []), content) |
| 63 | + content = update_language_section(language_stats, content) |
| 64 | + |
| 65 | + with open('README.md', 'w', encoding='utf-8') as file: |
| 66 | + file.write(content) |
| 67 | + |
| 68 | + # Save detailed stats for historical tracking |
| 69 | + stats_dir = Path('.github/stats') |
| 70 | + stats_dir.mkdir(exist_ok=True) |
| 71 | + |
| 72 | + timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M') |
| 73 | + stats_file = stats_dir / f'stats_{timestamp}.json' |
| 74 | + |
| 75 | + full_stats = { |
| 76 | + 'repository': stats, |
| 77 | + 'trending': trending_repos, |
| 78 | + 'languages': language_stats, |
| 79 | + 'topics': topic_stats, |
| 80 | + 'timestamp': timestamp |
| 81 | + } |
| 82 | + |
| 83 | + with open(stats_file, 'w', encoding='utf-8') as f: |
| 84 | + json.dump(full_stats, f, indent=2) |
| 85 | + |
| 86 | +if __name__ == "__main__": |
| 87 | + main() |
0 commit comments