<jupyter_start><jupyter_text>GitHub - Get stargazers from repository **Tags:** github stars naas_drivers operations analytics dataframe html plotly **Author:** [<NAME>](https://www.linkedin.com/in/sanjeet-attili-760bab190/) This notebook enables you to get a dataframe of all the stargazers of a particular Github repository.  Input  Imports<jupyter_code>import pandas as pd
import requests
import os
from urllib.parse import urlencode
from datetime import datetime
import plotly.graph_objects as go
from naas_drivers import github<jupyter_output><empty_output><jupyter_text>Variables<jupyter_code>REPO_URL = "https://github.com/jupyter-naas/awesome-notebooks"
GITHUB_TOKEN = "gh<PASSWORD>xxxxxxxxxxxxxxxxxxxxxxxxxxxx"<jupyter_output><empty_output><jupyter_text>Model  Get stargazers<jupyter_code>df_stargazers = github.connect(GITHUB_TOKEN).repos.get_stargazers(REPO_URL)
df_stargazers<jupyter_output><empty_output><jupyter_text>Output  Plotting a line chart to get trend<jupyter_code>def get_trend(df,
              date_col_name='STARRED_AT',
              value_col_name="ID",
              date_order='asc'):
    
    # Format date
    df[date_col_name] = pd.to_datetime(df[date_col_name]).dt.strftime("%Y-%m-%d")
    df = df.groupby(date_col_name, as_index=False).agg({value_col_name: "count"})
    d = datetime.now().date()
    d2 = df.loc[df.index[0], date_col_name]
    idx = pd.date_range(d2, d, freq = "D")
    
    df.set_index(date_col_name, drop=True, inplace=True)
    df.index = pd.DatetimeIndex(df.index)
    df = df.reindex(idx, fill_value=0)
    df[date_col_name] = pd.DatetimeIndex(df.index)
    
    # Calc sum cum
    df["value_cum"] = df.agg({value_col_name: "cumsum"})
    return df.reset_index(drop=True)

df_trend = get_trend(df_stargazers)
df_trend.tail(1)
def create_linechart(df, date, value, repo_url):
    # Get repo name
    repo_name = repo_url.split("https://github.com/")[-1].split("/")[-1]
    
    # Get last value
    last_value = df.loc[df.index[-1], value]
    
    # Init
    fig = go.Figure()
    
    # Create fig
    fig.add_trace(
        go.Scatter(
            x=df[date].to_list(),
            y=df[value].to_list(),
            mode="lines+text",
            line=dict(color="black"),
        )
    )
    fig.update_traces(marker_color='black')
    fig.update_layout(
        title=f"⭐<b> Stars - {repo_name}</b><br><span style='font-size: 13px;'>Total stars as of today: {last_value}</span>",
        title_font=dict(family="Arial", size=18, color="black"),
        plot_bgcolor="#ffffff",
        width=1200,
        height=800,
        paper_bgcolor="white",
        xaxis_title="Date",
        xaxis_title_font=dict(family="Arial", size=11, color="black"),
        yaxis_title='No. of stars',
        yaxis_title_font=dict(family="Arial", size=11, color="black"),
        margin_pad=10,
    )
    fig.show()
    return fig

fig = create_linechart(df_trend, "STARRED_AT", "value_cum", REPO_URL)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13541666666666666, 'fraction_numerical': 0.010416666666666666, 'mean_word_length': 3.824959481361426, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '99316', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1070, 'n_words': 180, 'path': 'GitHub/GitHub_Get_stargazers_from_repository.ipynb', 'repo_name': 'krajai/testt', 'size': '2985'}