za3karia commited on
Commit
f498a5f
·
verified ·
1 Parent(s): 029f640

Update functions.py

Browse files
Files changed (1) hide show
  1. functions.py +35 -0
functions.py CHANGED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from datetime import datetime, timedelta
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+ import numpy as np
6
+ from collections import defaultdict
7
+ import pathlib
8
+ import textwrap
9
+ import json
10
+ from tqdm import tqdm
11
+
12
+ # Assuming secrets is a module or a dictionary containing secrets
13
+ from streamlit import secrets
14
+
15
+ # Constants
16
+ GITHUB_API = "https://api.github.com"
17
+ # No default TOKEN assignment here, we will handle it dynamically
18
+
19
+ # Function to update headers with a new token
20
+ def get_headers(updated_token=None):
21
+ # Use the provided token or fallback to the existing secret token
22
+ token = updated_token if updated_token else secrets['GITHUB_API_TOKEN']
23
+ return {
24
+ "Authorization": f"token {token}",
25
+ "Accept": "application/vnd.github.v3+json"
26
+ }
27
+
28
+ # Example of refactored function to accept an optional token parameter
29
+ def get_contributors(repo, updated_token=None):
30
+ headers = get_headers(updated_token)
31
+ url = f"{GITHUB_API}/repos/{repo}/contributors"
32
+ response = requests.get(url, headers=headers)
33
+ return [contributor['login'] for contributor in response.json()]
34
+
35
+