diff --git a/data/ghstats.db b/data/ghstats.db deleted file mode 100644 index 4afa5c2..0000000 Binary files a/data/ghstats.db and /dev/null differ diff --git a/run.py b/run.py deleted file mode 100644 index 25ba53f..0000000 --- a/run.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python3 -""" -Entry point for running the GitHub profile widget generator. -Run this from the project root directory. -""" - -import sys -from src.generate import main - -if __name__ == "__main__": - main() diff --git a/src/README.md b/src/README.md deleted file mode 100644 index afd41c8..0000000 --- a/src/README.md +++ /dev/null @@ -1,112 +0,0 @@ -# GitHub Profile Widget Generator - -A modular system for generating polished SVG widgets from GitHub profile data. - -## Project Structure - -``` -src/ -├── models/ # Data classes and types -│ ├── __init__.py -│ └── types.py # Widget data models -│ -├── themes/ # Color schemes and styling -│ ├── __init__.py -│ └── themes.py # Theme definitions -│ -├── widgets/ # Widget rendering modules -│ ├── __init__.py -│ ├── grade.py # Developer grade widget -│ ├── impact.py # Impact timeline chart -│ ├── collaborators.py # Top collaborators -│ ├── focus.py # Focus areas bars -│ ├── languages.py # Languages donut chart -│ ├── achievements.py # Achievements list -│ └── composite.py # Full widget composer -│ -├── data/ # Data fetching and processing -│ ├── __init__.py -│ ├── fetcher.py # GitHub API client -│ └── processor.py # Data transformation -│ -├── utils/ # Helper functions -│ ├── __init__.py -│ └── svg_helpers.py # SVG utilities -│ -└── generate.py # Main CLI entry point -``` - -## Usage - -Run from the project root directory: - -```bash -# Generate widgets for a user -python run.py [theme] - -# Or run as a module -python -m src.generate [theme] - -# With GitHub token for higher rate limits -GITHUB_TOKEN=your_token python run.py - -# Use light theme -python run.py light -``` - -## Extending - -### Adding a New Widget - -1. Create a new file in `widgets/` (e.g., `widgets/my_widget.py`) -2. Implement `render_my_widget(data, theme_name="dark") -> str` -3. Add to `widgets/__init__.py` exports -4. Update `data/processor.py` to include it in `generate_widgets_from_github()` - -### Adding a New Theme - -1. Add theme definition to `themes/themes.py` -2. Use the theme name when calling `generate_full_widget(theme="my_theme")` - -## Configuration - -Customize behavior via environment variables: - -```bash -# Collaborator settings -export COLLABORATOR_MIN_COMMITS=10 # Min commits to be a collaborator (default: 10) -export COLLABORATOR_MAX_REPO_SIZE=100 # Skip repos with 100+ contributors (default: 100) -export COLLABORATOR_TOP_REPOS=5 # Check top N repos for collaborators (default: 5) - -# Commit fetching -export COMMIT_MAX_REPOS=10 # Fetch commits from top N repos (default: 10) -export COMMIT_PER_REPO=30 # Commits per repo (default: 30) - -# API settings -export API_TIMEOUT=5 # Request timeout in seconds (default: 5) - -# Run with custom settings -COLLABORATOR_MIN_COMMITS=15 python run.py username -``` - -## How Collaborators Are Detected - -The widget finds **meaningful collaborators** by: - -1. **Identifying shared repositories**: Looks at repos where the user has committed -2. **Fetching contributors**: Gets all contributors from those repos -3. **Applying thresholds**: - - Only includes contributors with 10+ commits (configurable) - - Filters out huge OSS projects (100+ contributors) - - Focuses on user's top 5 most active repos -4. **Ranking by collaboration**: Sorts by total shared commits across all repos - -This ensures collaborators are people you've actually worked with closely, not random contributors from large open-source projects. - -## Development - -All widgets follow the same pattern: -- Accept data models from `models/` -- Use themes from `themes/` -- Return SVG strings -- Use `utils.card_wrapper()` for consistent styling diff --git a/src/fetcher_api.py b/src/fetcher_api.py deleted file mode 100644 index db7352d..0000000 --- a/src/fetcher_api.py +++ /dev/null @@ -1,78 +0,0 @@ -"""Flask API for the fetcher service. - -Pulls data from the GitHub API and writes it to the shared SQLite database. -Does not render anything. Runs independently from the generator. - - python -m src.fetcher_api # serves on :5001 - -Endpoints: - GET /health - POST /fetch {username, token?} -> fetches + upserts - GET /users -> list stored usernames - GET /users/ -> full stored payload -""" - -import os -from flask import Flask, jsonify, request - -from .data.fetcher import fetch_github_data -from .db import init_db, upsert_user, get_user, list_users, DUMMY_USERNAME - - -app = Flask(__name__) - - -@app.route("/health", methods=["GET"]) -def health(): - return jsonify({"status": "ok", "service": "fetcher"}) - - -@app.route("/fetch", methods=["POST"]) -def fetch(): - body = request.get_json(silent=True) or {} - username = body.get("username") - if not username: - return jsonify({"error": "username is required"}), 400 - if username == DUMMY_USERNAME: - return jsonify({"error": "cannot overwrite dummy user"}), 400 - - token = body.get("token") or os.environ.get("GITHUB_PAT") - - try: - data = fetch_github_data(username, token) - except Exception as e: - return jsonify({"error": f"fetch failed: {e}"}), 502 - - if not data.get("user") or data["user"].get("message") == "Not Found": - return jsonify({"error": f"github user '{username}' not found"}), 404 - - upsert_user(username, data) - return jsonify({ - "username": username, - "stored": True, - "total_commits": data.get("total_commits", 0), - "repos": len(data.get("repos", [])), - }) - - -@app.route("/users", methods=["GET"]) -def users_list(): - return jsonify(list_users()) - - -@app.route("/users/", methods=["GET"]) -def users_get(username: str): - data = get_user(username) - if data is None: - return jsonify({"error": "not found"}), 404 - return jsonify(data) - - -def main(): - init_db() - port = int(os.environ.get("FETCHER_PORT", "5001")) - app.run(host="0.0.0.0", port=port, debug=False) - - -if __name__ == "__main__": - main() diff --git a/src/generate.py b/src/generate.py deleted file mode 100644 index 2fde4f2..0000000 --- a/src/generate.py +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env python3 -""" -GitHub Profile Widget Generator -Generates polished SVG mini-widgets from GitHub profile data. -""" - -import sys -import os -from typing import Optional - -from .models import AchievementData -from .data.fetcher import fetch_github_data -from .data.processor import generate_widgets_from_github -from .widgets import render_achievements_widget, compose_widget - - -def generate_full_widget( - username: str, - token: Optional[str] = None, - theme: str = "dark", - enabled: Optional[list[str]] = None, - widget_order: Optional[list[str]] = None, - achievements: Optional[list[AchievementData]] = None, - custom_tags: Optional[list[str]] = None, - hidden_languages: Optional[list[str]] = None, -) -> str: - """ - Generate a complete profile widget for a GitHub user. - - Args: - username: GitHub username - token: GitHub API token - theme: Color theme name - enabled: List of widgets to include (None = use config default) - widget_order: Order of widgets (None = use config default) - achievements: Custom achievements to display - custom_tags: Custom tags to add to grade widget (e.g., ["open-source", "hackathon-winner"]) - hidden_languages: Languages to exclude from stats (e.g., ["HTML", "CSS"]) - """ - from .config import ENABLED_WIDGETS, WIDGET_ORDER, HIDDEN_LANGUAGES - - if enabled is None: - enabled = ENABLED_WIDGETS - - if widget_order is None: - widget_order = WIDGET_ORDER - - if hidden_languages is None: - hidden_languages = HIDDEN_LANGUAGES - - print(f"Fetching GitHub data for {username}...") - github_data = fetch_github_data(username, token) - - # Log contribution counts - total_commits = github_data.get("total_commits", 0) - recent_commits = github_data.get("recent_commits", 0) - total_prs = github_data.get("total_prs", 0) - daily_commits = len(github_data.get("commits", [])) - - if total_commits > 0: - print(f" Total contributions (all-time): {total_commits:,}") - print(f" Recent contributions (6 months): {recent_commits:,}") - print(f" Total PRs (all-time): {total_prs:,}") - print(f" Daily contribution data points: {daily_commits}") - else: - print(f" Warning: Could not fetch contribution count") - if daily_commits == 0: - print(f" Try running with GITHUB_PAT environment variable") - - print("Generating widgets...") - widgets = generate_widgets_from_github( - github_data, - theme, - custom_tags=custom_tags, - hidden_languages=hidden_languages, - enabled=enabled, - ) - - if achievements and "achievements" in enabled: - widgets["achievements"] = render_achievements_widget( - achievements, theme - ) - - # Save individual widgets - for name, svg in widgets.items(): - if svg: - with open(f"widget_{name}.svg", "w") as f: - f.write(svg) - print(f" Saved widget_{name}.svg") - - print("Composing final widget...") - # Order widgets according to widget_order - ordered_enabled = [w for w in widget_order if w in enabled and w in widgets and widgets[w]] - - composite = compose_widget( - widgets=widgets, - enabled=ordered_enabled, - theme_name=theme, - username=username, - avatar_b64=github_data.get("avatar_b64", ""), - ) - - with open(f"widget_{username}.svg", "w") as f: - f.write(composite) - print(f" Saved widget_{username}.svg") - - return composite - - -def main(): - """CLI entry point.""" - username = sys.argv[1] if len(sys.argv) > 1 else "shaymanor" - token = os.environ.get("GITHUB_PAT") - theme = sys.argv[2] if len(sys.argv) > 2 else "dark" - - if username: - achievements = [ - AchievementData( - "MIT IQuHACK Winner", - "1st Place · Quantum Track", - "2025-01", - "trophy", - ), - AchievementData( - "MLH Top 50", "Global Hackathon League", "2025", "medal" - ), - ] - - # Example custom tags - uncomment to add custom badges - # custom_tags = ["open-source", "hackathon-winner", "quantum-computing"] - custom_tags = ["Testing"] - - generate_full_widget(username, token, theme, achievements=achievements, custom_tags=custom_tags) - else: - print("Usage: python generate.py [theme]") - sys.exit(1) - - -if __name__ == "__main__": - main() diff --git a/src/generator_api.py b/src/generator_api.py deleted file mode 100644 index db749b1..0000000 --- a/src/generator_api.py +++ /dev/null @@ -1,149 +0,0 @@ -"""Flask API for the generator service. - -Reads previously-fetched data from the shared SQLite database and renders -SVG widgets. Never calls the fetcher — if the requested user is missing or -has incomplete data, it falls back to the __dummy__ user seeded in the DB. - - python -m src.generator_api # serves on :5002 - -Endpoints: - GET /health - POST /generate {username, theme?, widgets?, widget_order?, - custom_tags?, hidden_languages?, format?} - -> SVG string (format=svg, default) or - JSON {widgets: {...}, composite, used_dummy} -""" - -import os -from flask import Flask, jsonify, request, Response - -from .db import init_db, get_user, DUMMY_USERNAME, REQUIRED_FIELDS -from .data.processor import generate_widgets_from_github -from .models import AchievementData -from .widgets import compose_widget, render_achievements_widget -from .config import ENABLED_WIDGETS, WIDGET_ORDER - - -app = Flask(__name__) - - -def _load_with_fallback(username: str) -> tuple[dict, bool]: - """Return (github_data, used_dummy). - - If the row is missing or is missing any REQUIRED_FIELDS, swap in the dummy - payload wholesale (no partial merging). - """ - data = get_user(username) - if data is None or any(f not in data for f in REQUIRED_FIELDS): - dummy = get_user(DUMMY_USERNAME) - if dummy is None: - raise RuntimeError("dummy user missing from database; run init_db") - return dummy, True - return data, False - - -@app.route("/health", methods=["GET"]) -def health(): - return jsonify({"status": "ok", "service": "generator"}) - - -@app.route("/generate", methods=["POST"]) -def generate(): - body = request.get_json(silent=True) or {} - username = body.get("username") - if not username: - return jsonify({"error": "username is required"}), 400 - - theme = body.get("theme", "dark") - enabled = body.get("widgets") or ENABLED_WIDGETS - widget_order = body.get("widget_order") or WIDGET_ORDER - custom_tags = body.get("custom_tags") - hidden_languages = body.get("hidden_languages") - achievements_raw = body.get("achievements") or [] - widget_settings = body.get("widget_settings") or {} - fmt = body.get("format", "svg") - - github_data, used_dummy = _load_with_fallback(username) - - widgets = generate_widgets_from_github( - github_data, - theme=theme, - custom_tags=custom_tags, - hidden_languages=hidden_languages, - enabled=enabled, - widget_settings=widget_settings, - ) - - # Render achievements if provided and enabled - if "achievements" in enabled and achievements_raw: - achs = [ - AchievementData( - title=a.get("title", ""), - subtitle=a.get("subtitle", ""), - event_date=a.get("event_date", ""), - icon=a.get("icon", "trophy"), - ) - for a in achievements_raw - if a.get("title") - ] - if achs: - widgets["achievements"] = render_achievements_widget(achs, theme, settings=widget_settings.get("achievements")) - - ordered = [w for w in widget_order if w in enabled and w in widgets and widgets[w]] - display_name = username if not used_dummy else username - composite = compose_widget( - widgets=widgets, - enabled=ordered, - theme_name=theme, - username=display_name, - avatar_b64=github_data.get("avatar_b64", ""), - ) - - if fmt == "data": - # Return raw computed data for client-side rendering - from .data.processor import ( - compute_grade, compute_impact_timeline, - compute_collaborators, compute_focus, compute_languages, - ) - raw = {} - if "grade" in enabled: - g = compute_grade(github_data, custom_tags=custom_tags) - raw["grade"] = {"grade": g.grade, "score": g.score, "stats": g.stats, - "tags": [{"tag": t.tag, "source": t.source, "confidence": t.confidence} for t in g.tags], - "breakdown": g.breakdown} - if "impact" in enabled: - raw["impact"] = [{"week_start": w.week_start, "commits": w.commits} - for w in compute_impact_timeline(github_data)] - if "collaborators" in enabled: - raw["collaborators"] = [{"username": c.username, "shared_repos": c.shared_repos, - "shared_commits": c.shared_commits} - for c in compute_collaborators(github_data)] - if "focus" in enabled: - raw["focus"] = [{"category": f.category, "percentage": f.percentage, - "commit_count": f.commit_count} - for f in compute_focus(github_data, hidden_languages=hidden_languages)] - if "languages" in enabled: - raw["languages"] = [{"language": l.language, "percentage": l.percentage, "loc": l.loc} - for l in compute_languages(github_data, hidden_languages=hidden_languages)] - return jsonify({"username": username, "used_dummy": used_dummy, "data": raw}) - - if fmt == "json": - return jsonify({ - "username": username, - "used_dummy": used_dummy, - "widgets": widgets, - "composite": composite, - }) - - headers = {"X-Used-Dummy": "1" if used_dummy else "0"} - return Response(composite, mimetype="image/svg+xml", headers=headers) - - -def main(): - init_db() - port = int(os.environ.get("GENERATOR_PORT", "5002")) - app.run(host="0.0.0.0", port=port, debug=False) - - -if __name__ == "__main__": - main()