Skip to content
Open
Show file tree
Hide file tree
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
Binary file added .DS_Store
Binary file not shown.
193 changes: 193 additions & 0 deletions LabsAPI.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "58f23589-5458-4d29-8e5f-36b99deb6e5a",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "fdd556e9-5c37-4044-bd90-0d35c3c0c7ec",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter GitHub username: lewisdeanclark\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requesting: https://api.github.com/users/lewisdeanclark\n"
]
}
],
"source": [
"import requests\n",
"\n",
"def get_github_user(username):\n",
" username = username.strip()\n",
" url = f\"https://api.github.com/users/{username}\"\n",
" print(f\"Requesting: {url}\")\n",
" \n",
" response = requests.get(url)\n",
" \n",
" if response.status_code == 200:\n",
" return response.json()\n",
" elif response.status_code == 404:\n",
" print(\"User not found. Please check the username.\")\n",
" else:\n",
" print(f\"Error {response.status_code}: {response.text}\")\n",
" \n",
" return None\n",
"\n",
"username = input(\"Enter GitHub username: \")\n",
"user_data = get_github_user(username)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "a8ad7096-5cc1-4477-9cb7-54035d590dd3",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter GitHub username: paulmillr\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"--- Profile Info ---\n",
"Name: Paul Miller\n",
"Bio: None\n",
"Location: None\n",
"Public repos: 60\n",
"Followers: 4195\n",
"Following: 0\n",
"\n",
"--- Most Used Languages ---\n",
"JavaScript: 23 repos\n",
"TypeScript: 22 repos\n",
"Python: 2 repos\n",
"Vue: 2 repos\n",
"C++: 1 repos\n",
"Shell: 1 repos\n",
"Vim script: 1 repos\n",
"C: 1 repos\n",
"Rust: 1 repos\n",
"CoffeeScript: 1 repos\n",
"\n",
"--- Popular Projects (Top Starred) ---\n",
"chokidar - ⭐ 11553 - https://github.com/paulmillr/chokidar\n",
"encrypted-dns - ⭐ 3959 - https://github.com/paulmillr/encrypted-dns\n",
"es6-shim - ⭐ 3113 - https://github.com/paulmillr/es6-shim\n",
"dotfiles - ⭐ 1225 - https://github.com/paulmillr/dotfiles\n",
"exoskeleton - ⭐ 877 - https://github.com/paulmillr/exoskeleton\n"
]
}
],
"source": [
"import requests\n",
"from collections import Counter ### good for using on the analyze_language\n",
"\n",
"def get_github_user(username):\n",
" url = f\"https://api.github.com/users/{username}\"\n",
" response = requests.get(url)\n",
" if response.status_code == 200: ### so this is for having the user input their username\n",
" return response.json()\n",
" else:\n",
" print(\"User not found or error occurred.\")\n",
" return None\n",
"\n",
"def get_user_repos(username):\n",
" url = f\"https://api.github.com/users/{username}/repos?per_page=100\"\n",
" response = requests.get(url)\n",
" if response.status_code == 200:\n",
" return response.json()\n",
" else:\n",
" print(\"Could not fetch repositories.\")\n",
" return []\n",
"\n",
"def analyze_languages(repos):\n",
" languages = [repo['language'] for repo in repos if repo['language']]\n",
" return Counter(languages).most_common()\n",
"\n",
"def get_top_starred_repos(repos, top_n=5):\n",
" return sorted(repos, key=lambda r: r['stargazers_count'], reverse=True)[:top_n]\n",
"\n",
"def main():\n",
" username = input(\"Enter GitHub username: \").strip()\n",
" profile = get_github_user(username)\n",
" if not profile:\n",
" return\n",
"\n",
" repos = get_user_repos(username)\n",
"\n",
" print(\"\\n--- Profile Info ---\")\n",
" print(f\"Name: {profile.get('name')}\")\n",
" print(f\"Bio: {profile.get('bio')}\")\n",
" print(f\"Location: {profile.get('location')}\")\n",
" print(f\"Public repos: {profile.get('public_repos')}\")\n",
" print(f\"Followers: {profile.get('followers')}\")\n",
" print(f\"Following: {profile.get('following')}\")\n",
"\n",
" print(\"\\n--- Most Used Languages ---\")\n",
" for lang, count in analyze_languages(repos):\n",
" print(f\"{lang}: {count} repos\")\n",
"\n",
" print(\"\\n--- Popular Projects (Top Starred) ---\")\n",
" top_repos = get_top_starred_repos(repos)\n",
" for repo in top_repos:\n",
" print(f\"{repo['name']} - ⭐ {repo['stargazers_count']} - {repo['html_url']}\")\n",
"\n",
"if __name__ == \"__main__\":\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "60e0c695-80bb-4d8e-af91-8728312c9ff5",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "conda-base-py"
},
"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.13.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}