File size: 1,984 Bytes
d718b09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st 
import requests
import pandas as pd 
from pandas import json_normalize
import plotly.express as px 

def create_stargazers_count(user,repo):
    """this function creates the stargazers count dataframe"""

    star_count_url = "https://api.github.com/repos/"+user+"/"+repo
    response = requests.request("GET", star_count_url)
    total_star_count = response.json()['stargazers_count']
    loops = int(total_star_count / 100) + 1
    star_trends_url = "https://api.github.com/repos/"+user+"/"+repo+"/stargazers"
    star_trends_resp = []
    headers = {
    "Accept": "application/vnd.github.v3.star+json",
    "content-type": "application/json"
    }
    for page in range(loops):
        response = requests.request("GET", star_trends_url+"?per_page=100"+"&page="+str(page+1), headers=headers).json()
        star_trends_resp.extend(response)

    df = json_normalize(star_trends_resp)

    df['starred_date'] = pd.to_datetime(df['starred_at']).dt.date

    star_trend_df = df.groupby(['starred_date'])['starred_date'].count().cumsum().reset_index(name="count")

    return star_trend_df


st.title("⭐️ Github Star Tracking ⭐️")

st.subheader("with interactive ⭐️ History chart")

st.image("https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fpngimg.com%2Fuploads%2Fgithub%2Fgithub_PNG93.png&f=1&nofb=1",
width=200)

st.markdown("### Github Repo Details")

first,second = st.columns(2)

with first:
    user = st.text_input(label="Enter the github user name", value =  "amrrs")

with second:
    repo = st.text_input(label="Enter the github repo name (without the user name)", value =  "coinmarketcapr")

st.write("You are going to see the star trends for this repo:" + user+"/"+repo +"/")


with st.spinner("Downloading Data from Github.....Stars are coming....."):
    df = create_stargazers_count(user,repo)

st.markdown("### Github Stars Trend")

chart = px.line(data_frame=df, x = 'starred_date', y = 'count')

st.plotly_chart(chart)