Created
November 11, 2023 13:21
-
-
Save encima/74afb70f1a72fe853417866963baef52 to your computer and use it in GitHub Desktop.
Github vs Linkedin Activity Visualizer Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from datetime import datetime, timedelta | |
import dash | |
from dash import html, dcc | |
import plotly.graph_objs as go | |
from dash.dependencies import Input, Output | |
from bs4 import BeautifulSoup | |
# GitHub setup | |
GITHUB_TOKEN = 'your_github_token_here' # Replace with your GitHub token | |
ORGANIZATION = 'womenplusplus' | |
# Get Github activity (i.e. https://api.github.com/orgs/womenplusplus/events) | |
def get_github_activity(): | |
headers = {'Authorization': f'token {GITHUB_TOKEN}'} | |
yesterday = datetime.now() - timedelta(days=1) | |
date_str = yesterday.strftime('%Y-%m-%d') | |
url = f'https://api.github.com/orgs/{ORGANIZATION}/events' | |
response = requests.get(url, headers=headers) | |
events = response.json() | |
# TODO Count events for the specified day | |
count = 10 | |
return count | |
# Get linkedin posts via BeautifulSoup (i.e. URL https://www.linkedin.com/search/results/content/?keywords=womenplusplus&origin=SWITCH_SEARCH_VERTICAL&sid=Dq6) | |
def get_linkedin_activity(): | |
# TODO get Linkedin data here | |
linkedin_count = 10 # Placeholder count | |
return linkedin_count | |
# Initialize Dash app | |
app = dash.Dash(__name__) | |
app.layout = html.Div([ | |
dcc.Graph(id='github-vs-linkedin'), | |
dcc.Interval( | |
id='interval-component', | |
interval=1*86400000, # in milliseconds (1 day) | |
n_intervals=0 | |
) | |
]) | |
# Update function for the Dash app | |
@app.callback(Output('github-vs-linkedin', 'figure'), | |
[Input('interval-component', 'n_intervals')]) | |
def update_graph(n): | |
# Fetch GitHub and LinkedIn data | |
github_count = get_github_activity() | |
linkedin_count = get_linkedin_activity() | |
# Create the bar graph | |
fig = go.Figure(data=[ | |
go.Bar(name='GitHub', x=['GitHub'], y=[github_count]), | |
go.Bar(name='LinkedIn', x=['LinkedIn'], y=[linkedin_count]) | |
]) | |
# Update layout | |
fig.update_layout(barmode='group') | |
return fig | |
# Run the app | |
if __name__ == '__main__': | |
app.run_server(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment