|
| 1 | +import requests |
| 2 | +import pandas as pd |
| 3 | +import json |
| 4 | +import textwrap |
| 5 | +from datetime import date |
| 6 | + |
| 7 | + |
| 8 | +url = "https://api.github.com/repos/modeci/modelspec/contributors" |
| 9 | + |
| 10 | +response = requests.get(url=url, auth=("<github_username>", "<github_token>")) |
| 11 | + |
| 12 | +json_data = response.json() |
| 13 | + |
| 14 | +df = pd.DataFrame(json_data) |
| 15 | + |
| 16 | +per_info = list(df["url"].unique()) |
| 17 | +len_per_info = len(per_info) |
| 18 | + |
| 19 | +empty_list = [] |
| 20 | +for i in range(len_per_info): |
| 21 | + url = per_info[i] |
| 22 | + print(url) |
| 23 | + data = requests.get(url=url) |
| 24 | + requests_status = "unknown" |
| 25 | + while (requests_status == "unknown") or (requests_status == "unsuccessful"): |
| 26 | + if data.status_code == 200: |
| 27 | + requests_status = "successful" |
| 28 | + empty_list.append(data.json()) |
| 29 | + else: |
| 30 | + # handle failure on requests to the url for mac os |
| 31 | + requests_status = "unsuccessful" |
| 32 | + print(f"Failed to get data from: {url}") |
| 33 | + # make request again to get data from the url |
| 34 | + data = requests.get(url=url) |
| 35 | + |
| 36 | +df1 = pd.DataFrame(empty_list) |
| 37 | +df1["name"] = df1["name"].fillna("") |
| 38 | +name = df1["name"] |
| 39 | +login = df1["login"] |
| 40 | +url_html = df1["html_url"] |
| 41 | +url_id = df1["id"] |
| 42 | + |
| 43 | +login_html = list(zip(name, login, url_html)) |
| 44 | +zip_dict = dict(zip(url_id, login_html)) |
| 45 | + |
| 46 | +file = "sphinx/source/api/Contributors.md" |
| 47 | +with open(file, "w") as f: |
| 48 | + print( |
| 49 | + textwrap.dedent( |
| 50 | + """\ |
| 51 | + (Modelspec:contributors)= |
| 52 | +
|
| 53 | + # Modelspec contributors |
| 54 | +
|
| 55 | + This page list names and Github profiles of contributors to Modelspec, listed in no particular order. |
| 56 | + This page is generated periodically, most recently on {}.""".format( |
| 57 | + date.today() |
| 58 | + ) |
| 59 | + ), |
| 60 | + file=f, |
| 61 | + ) |
| 62 | + |
| 63 | + print("", file=f) |
| 64 | + |
| 65 | + for key, val in zip_dict.items(): |
| 66 | + print("- {} ([@{}]({}))".format(val[0], val[1], val[2]), file=f) |
0 commit comments