forked from terpinedream/tuxagotchi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.py
More file actions
29 lines (24 loc) · 870 Bytes
/
github.py
File metadata and controls
29 lines (24 loc) · 870 Bytes
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
# Github API interactions
import requests
from datetime import datetime, timezone
def get_recent_commits(username, repo, per_page=30):
"""
Fetches the latest commits for a repo. Returns a list of commit data.
"""
url = f"https://api.github.com/repos/{username}/{repo}/commits"
params = {"per_page": per_page}
try:
response = requests.get(url, params=params)
response.raise_for_status()
return response.json()
except Exception as e:
print(f"[DEBUG] Failed to fetch commits: {e}")
return []
def get_recent_commit_time(username, repo):
commits = get_recent_commits(username, repo)
if commits:
commit_time = commits[0]["commit"]["committer"]["date"]
return datetime.strptime(commit_time, "%Y-%m-%dT%H:%M:%SZ").replace(
tzinfo=timezone.utc
)
return None