Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
292 changes: 292 additions & 0 deletions Lab_API_Github_Lucie.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "8f51a92d",
"metadata": {},
"outputs": [],
"source": [
"#GitHub Profile Analyzer — a tool that connects to the GitHub API to fetch and display useful information about a user's public GitHub account.\n",
"#You’ll start by allowing a user to enter a GitHub username, then retrieve and show key details such as their profile info, list of public repositories, most-used programming languages, and popular projects.\n",
"\n",
"## Expected output:\n",
"\n",
"# GitHub Profile: torvalds\n",
"# Name: Linus Torvalds\n",
"# Username: torvalds\n",
"# Bio: Software engineer, creator of Linux\n",
"# Public Repos: 6\n",
"# Followers: 250K\n",
"# Following: 0\n",
"# Location: Portland, OR\n",
"# Profile URL: https://github.com/torvalds\n",
"\n",
"# Repositories ---------------------\n",
"\n",
"# project1\n",
"# View Repo (link here)\n",
"# Stars: 160K\n",
"# Language: C\n",
"# Last Updated: 2024-10-02\n",
"\n",
"# project2\n",
"# View Repo (link here)\n",
"# Stars: 4.5K\n",
"# Language: C++\n",
"# Last Updated: 2023-09-18\n",
"\n",
"# project3\n",
"# View Repo (link here)\n",
"# Stars: 230\n",
"# Language: Assembly\n",
"# Last Updated: 2021-01-11\n",
"\n",
"\n",
"# Most Used Languages\n",
"# Python (80%)\n",
"# SQL (10%)\n",
"\n",
"# Most Starred Repos\n",
"# project1 – 160K stars\n",
"# project2 – 4.5K stars\n",
"# linux-project3 – 1.2K stars"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "2b055867",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"from collections import Counter\n",
"from datetime import datetime"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "f47a20a1",
"metadata": {},
"outputs": [],
"source": [
"#1 User \n",
"\n",
"def github_profile_analyzer(username):\n",
" \n",
" profile_url = f\"https://api.github.com/users/{username}\"\n",
" profile_data = requests.get(profile_url).json()\n",
"\n",
" if \"message\" in profile_data and profile_data[\"message\"] == \"Not Found\":\n",
" print(f\"❌ Utilisateur '{username}' introuvable sur GitHub.\")\n",
" return\n",
"\n",
" print(f\"GitHub Profile: {username}\")\n",
" print(f\"Name: {profile_data.get('name', 'N/A')}\")\n",
" print(f\"Username: {profile_data.get('login', 'N/A')}\")\n",
" print(f\"Bio: {profile_data.get('bio', 'N/A')}\")\n",
" print(f\"Public Repos: {profile_data.get('public_repos', 0)}\")\n",
" print(f\"Followers: {profile_data.get('followers', 0)}\")\n",
" print(f\"Following: {profile_data.get('following', 0)}\")\n",
" print(f\"Location: {profile_data.get('location', 'N/A')}\")\n",
" print(f\"Profile URL: {profile_data.get('html_url', '')}\")\n",
" print()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "3fb75e08",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"GitHub Profile: torvalds\n",
"Name: Linus Torvalds\n",
"Username: torvalds\n",
"Bio: None\n",
"Public Repos: 8\n",
"Followers: 243140\n",
"Following: 0\n",
"Location: Portland, OR\n",
"Profile URL: https://github.com/torvalds\n",
"\n"
]
}
],
"source": [
"github_profile_analyzer(\"torvalds\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "27c7a7e9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Repositories ---------------------\n",
"linux\n",
" View Repo: https://github.com/torvalds/linux\n",
" Stars: 199272\n",
" Language: C\n",
" Last Updated: 2025-08-09\n",
"\n",
"uemacs\n",
" View Repo: https://github.com/torvalds/uemacs\n",
" Stars: 1520\n",
" Language: C\n",
" Last Updated: 2025-08-09\n",
"\n",
"1590A\n",
" View Repo: https://github.com/torvalds/1590A\n",
" Stars: 388\n",
" Language: OpenSCAD\n",
" Last Updated: 2025-08-07\n",
"\n",
"test-tlb\n",
" View Repo: https://github.com/torvalds/test-tlb\n",
" Stars: 806\n",
" Language: C\n",
" Last Updated: 2025-08-05\n",
"\n",
"libgit2\n",
" View Repo: https://github.com/torvalds/libgit2\n",
" Stars: 209\n",
" Language: C\n",
" Last Updated: 2025-08-04\n",
"\n",
"libdc-for-dirk\n",
" View Repo: https://github.com/torvalds/libdc-for-dirk\n",
" Stars: 274\n",
" Language: C\n",
" Last Updated: 2025-08-03\n",
"\n",
"subsurface-for-dirk\n",
" View Repo: https://github.com/torvalds/subsurface-for-dirk\n",
" Stars: 337\n",
" Language: C++\n",
" Last Updated: 2025-07-27\n",
"\n",
"pesconvert\n",
" View Repo: https://github.com/torvalds/pesconvert\n",
" Stars: 443\n",
" Language: C\n",
" Last Updated: 2025-07-27\n",
"\n"
]
}
],
"source": [
"#2 Repositories\n",
"repos_url = f\"https://api.github.com/users/{username}/repos?per_page=100&sort=updated\"\n",
"repos_data = requests.get(repos_url).json()\n",
"\n",
"print(\"Repositories ---------------------\")\n",
"languages_counter = Counter()\n",
"starred_repos = []\n",
"\n",
"for repo in repos_data:\n",
" name = repo.get('name')\n",
" url = repo.get('html_url')\n",
" stars = repo.get('stargazers_count', 0)\n",
" language = repo.get('language') or \"N/A\"\n",
" updated_at = repo.get('updated_at')\n",
" updated_at = datetime.strptime(updated_at, \"%Y-%m-%dT%H:%M:%SZ\").date()\n",
"\n",
" print(f\"{name}\")\n",
" print(f\" View Repo: {url}\")\n",
" print(f\" Stars: {stars}\")\n",
" print(f\" Language: {language}\")\n",
" print(f\" Last Updated: {updated_at}\")\n",
" print()\n",
"\n",
" if language != \"N/A\":\n",
" languages_counter[language] += 1\n",
" starred_repos.append((name, stars))"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "de8386b8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Most Used Languages\n",
"C (75.0%)\n",
"OpenSCAD (12.5%)\n",
"C++ (12.5%)\n",
"\n"
]
}
],
"source": [
"#3 Most Used Languages \n",
"print(\"Most Used Languages\")\n",
"total_langs = sum(languages_counter.values())\n",
"for lang, count in languages_counter.most_common():\n",
" percent = (count / total_langs) * 100 if total_langs > 0 else 0\n",
" print(f\"{lang} ({percent:.1f}%)\")\n",
"print()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "ba1e893f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Most Starred Repos\n",
"linux – 199272 stars\n",
"uemacs – 1520 stars\n",
"test-tlb – 806 stars\n",
"pesconvert – 443 stars\n",
"1590A – 388 stars\n"
]
}
],
"source": [
"#Most Starred Repos \n",
"print(\"Most Starred Repos\")\n",
"for name, stars in sorted(starred_repos, key=lambda x: x[1], reverse=True)[:5]:\n",
" print(f\"{name} – {stars} stars\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}