Amrrs commited on
Commit
d718b09
·
1 Parent(s): 416d91c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import pandas as pd
4
+ from pandas import json_normalize
5
+ import plotly.express as px
6
+
7
+ def create_stargazers_count(user,repo):
8
+ """this function creates the stargazers count dataframe"""
9
+
10
+ star_count_url = "https://api.github.com/repos/"+user+"/"+repo
11
+ response = requests.request("GET", star_count_url)
12
+ total_star_count = response.json()['stargazers_count']
13
+ loops = int(total_star_count / 100) + 1
14
+ star_trends_url = "https://api.github.com/repos/"+user+"/"+repo+"/stargazers"
15
+ star_trends_resp = []
16
+ headers = {
17
+ "Accept": "application/vnd.github.v3.star+json",
18
+ "content-type": "application/json"
19
+ }
20
+ for page in range(loops):
21
+ response = requests.request("GET", star_trends_url+"?per_page=100"+"&page="+str(page+1), headers=headers).json()
22
+ star_trends_resp.extend(response)
23
+
24
+ df = json_normalize(star_trends_resp)
25
+
26
+ df['starred_date'] = pd.to_datetime(df['starred_at']).dt.date
27
+
28
+ star_trend_df = df.groupby(['starred_date'])['starred_date'].count().cumsum().reset_index(name="count")
29
+
30
+ return star_trend_df
31
+
32
+
33
+ st.title("⭐️ Github Star Tracking ⭐️")
34
+
35
+ st.subheader("with interactive ⭐️ History chart")
36
+
37
+ st.image("https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fpngimg.com%2Fuploads%2Fgithub%2Fgithub_PNG93.png&f=1&nofb=1",
38
+ width=200)
39
+
40
+ st.markdown("### Github Repo Details")
41
+
42
+ first,second = st.columns(2)
43
+
44
+ with first:
45
+ user = st.text_input(label="Enter the github user name", value = "amrrs")
46
+
47
+ with second:
48
+ repo = st.text_input(label="Enter the github repo name (without the user name)", value = "coinmarketcapr")
49
+
50
+ st.write("You are going to see the star trends for this repo:" + user+"/"+repo +"/")
51
+
52
+
53
+ with st.spinner("Downloading Data from Github.....Stars are coming....."):
54
+ df = create_stargazers_count(user,repo)
55
+
56
+ st.markdown("### Github Stars Trend")
57
+
58
+ chart = px.line(data_frame=df, x = 'starred_date', y = 'count')
59
+
60
+ st.plotly_chart(chart)