Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/GitHub/GitHub_Get_reactions_from_comment.ipynb
2973 views
Kernel: Python 3

GitHub.png

GitHub - Get reactions from comment

Give Feedback | Bug report

Tags: #github #reactions #automation #snippet

Author: Varsha Kumar

Last update: 2024-06-05 (Created: 2024-06-04)

Description: This notebook allows users to retrieve the reactions from a comment.

Input

Import libraries

import requests import pandas as pd import naas_python

Setup variables

  • github_token: personal token creates

  • reaction_url: link to the comments reaction data

github_token = naas_python.secret.get("GITHUB_TOKEN").value reactions_url = "https://api.github.com/repos/pola-rs/polars/issues/comments/2144455441/reactions"

Model

Get comment reactions

def get_comment_reactions(reactions_url): headers = { 'Authorization': f'token {github_token}', 'Accept': 'application/vnd.github.squirrel-girl-preview+json' # Required for reactions API } response = requests.get(reactions_url, headers=headers) print(f"Requesting: {reactions_url}") if response.status_code == 200: return response.json() else: print(f"Failed to fetch reactions: {response.status_code} - {response.text}") return [] reactions = get_comment_reactions(reactions_url)

Output

Display result

def print_reaction_types_table(reactions): if reactions: reaction_types = { '+1': 0, '-1': 0, 'laugh': 0, 'hooray': 0, 'confused': 0, 'heart': 0, 'rocket': 0, 'eyes': 0 } for reaction in reactions: reaction_content = reaction['content'] if reaction_content in reaction_types: reaction_types[reaction_content] += 1 # Convert the reaction types to a DataFrame reaction_data = pd.DataFrame(list(reaction_types.items()), columns=['Reaction Type', 'Count']) # Filter out reactions with a count of 0 filtered_reaction_data = reaction_data[reaction_data['Count'] > 0] print(filtered_reaction_data) else: print("No reactions found or failed to fetch reactions.") print_reaction_types_table(reactions)