-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_timeline.py
34 lines (28 loc) · 1.01 KB
/
github_timeline.py
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
from flask import Flask, render_template, request, redirect, url_for
import requests
app = Flask(__name__)
def get_github_timeline(username):
url = f"https://api.github.com/users/{username}/repos"
response = requests.get(url)
repos = response.json()
timeline = []
for repo in repos:
repo_info = {
"name": repo["name"],
"created_at": repo["created_at"],
"description": repo["description"]
}
timeline.append(repo_info)
return timeline
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "POST":
username = request.form["username"]
if username:
timeline = get_github_timeline(username)
return render_template("timeline.html", username=username, timeline=timeline)
else:
return render_template("index.html", error="Please enter a valid GitHub username.")
return render_template("index.html", error=None)
if __name__ == "__main__":
app.run(debug=True)