-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
91 lines (70 loc) · 2.54 KB
/
app.py
File metadata and controls
91 lines (70 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""git-aura - RPG-style developer trading cards from GitHub profiles."""
from flask import Flask, render_template, request, redirect, url_for, Response, jsonify
from generator import fetch_github_data, calculate_stats, generate_card_svg, determine_class, CLASSES
app = Flask(__name__)
@app.route("/")
def index():
"""Landing page with username input form."""
return render_template("index.html")
@app.route("/card/<username>")
def card(username):
"""Generate and display a card for a GitHub user."""
data = fetch_github_data(username)
if data is None:
return render_template("index.html", error=f"GitHub user '{username}' not found."), 404
stats = calculate_stats(data)
dev_class = determine_class(stats)
cls = CLASSES[dev_class]
svg = generate_card_svg(stats)
return render_template(
"card.html",
username=username,
stats=stats,
dev_class=dev_class,
cls=cls,
svg=svg,
)
@app.route("/api/card/<username>.svg")
def card_svg(username):
"""Return raw SVG card for embedding."""
data = fetch_github_data(username)
if data is None:
return Response("User not found", status=404)
stats = calculate_stats(data)
svg = generate_card_svg(stats)
return Response(svg, mimetype="image/svg+xml", headers={
"Cache-Control": "public, max-age=3600",
})
@app.route("/api/card/<username>.json")
def card_json(username):
"""Return card data as JSON."""
data = fetch_github_data(username)
if data is None:
return jsonify({"error": "User not found"}), 404
stats = calculate_stats(data)
dev_class = determine_class(stats)
return jsonify({
"username": stats["username"],
"name": stats["name"],
"class": dev_class,
"level": stats["level"],
"xp": stats["xp"],
"stats": {
"stars": stats["total_stars"],
"repos": stats["public_repos"],
"followers": stats["followers"],
"forks": stats["total_forks"],
"languages": stats["language_count"],
},
"top_languages": [{"name": l, "count": c} for l, c in stats["top_languages"]],
"svg_url": f"/api/card/{username}.svg",
})
@app.route("/search", methods=["POST"])
def search():
"""Handle search form submission."""
username = request.form.get("username", "").strip()
if not username:
return redirect(url_for("index"))
return redirect(url_for("card", username=username))
if __name__ == "__main__":
app.run(debug=True, port=5000)