Spaces:
Sleeping
Sleeping
Upload fetch_data.py
Browse files
github_analytics/fetch_data.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def fetch_user_data(username):
|
| 6 |
+
"""Fetches user and repository data from GitHub API."""
|
| 7 |
+
loading = st.empty() # Placeholder for loading indicator
|
| 8 |
+
error = st.empty() # Placeholder for error message
|
| 9 |
+
|
| 10 |
+
try:
|
| 11 |
+
user_response = requests.get(f"https://api.github.com/users/{username}")
|
| 12 |
+
user_data = user_response.json()
|
| 13 |
+
|
| 14 |
+
# Check if the user data contains a 'message' key indicating user not found
|
| 15 |
+
if 'message' in user_data and user_data['message'] == 'Not Found':
|
| 16 |
+
loading.empty() # Remove loading indicator
|
| 17 |
+
return "User not found", "Repo not found"
|
| 18 |
+
|
| 19 |
+
repo_response = requests.get(f"https://api.github.com/users/{username}/repos")
|
| 20 |
+
repo_data = repo_response.json()
|
| 21 |
+
|
| 22 |
+
loading.empty() # Remove loading indicator
|
| 23 |
+
return user_data, repo_data
|
| 24 |
+
|
| 25 |
+
except requests.exceptions.RequestException as e:
|
| 26 |
+
error.text = f"Error: {e}"
|
| 27 |
+
loading.empty() # Remove loading indicator
|
| 28 |
+
return None, None
|