diff --git a/GitHub/GitHub_Get_comments_from_issue_in_a_given_repository.ipynb b/GitHub/GitHub_Get_comments_and_reactions_from_issue.ipynb
similarity index 59%
rename from GitHub/GitHub_Get_comments_from_issue_in_a_given_repository.ipynb
rename to GitHub/GitHub_Get_comments_and_reactions_from_issue.ipynb
index 369e05202a..4f8cba5c32 100644
--- a/GitHub/GitHub_Get_comments_from_issue_in_a_given_repository.ipynb
+++ b/GitHub/GitHub_Get_comments_and_reactions_from_issue.ipynb
@@ -19,7 +19,7 @@
"tags": []
},
"source": [
- "# GitHub - Get comments and reactions from Issue\n",
+ "# GitHub - Get comments and reactions from issue\n",
"Give Feedback | Bug report"
]
},
@@ -80,28 +80,17 @@
"## Input"
]
},
- {
- "cell_type": "markdown",
- "id": "b483a140",
- "metadata": {
- "papermill": {},
- "tags": []
- },
- "source": [
- "### Import libraries"
- ]
- },
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 22,
"id": "353ef79c",
"metadata": {
"execution": {
- "iopub.execute_input": "2024-06-05T12:26:01.851334Z",
- "iopub.status.busy": "2024-06-05T12:26:01.851046Z",
- "iopub.status.idle": "2024-06-05T12:26:02.759162Z",
- "shell.execute_reply": "2024-06-05T12:26:02.758418Z",
- "shell.execute_reply.started": "2024-06-05T12:26:01.851256Z"
+ "iopub.execute_input": "2024-06-06T12:46:32.840909Z",
+ "iopub.status.busy": "2024-06-06T12:46:32.840683Z",
+ "iopub.status.idle": "2024-06-06T12:46:32.843884Z",
+ "shell.execute_reply": "2024-06-06T12:46:32.843118Z",
+ "shell.execute_reply.started": "2024-06-06T12:46:32.840886Z"
},
"papermill": {},
"tags": []
@@ -110,7 +99,8 @@
"source": [
"import requests\n",
"import re\n",
- "import pandas as pd"
+ "import pandas as pd\n",
+ "import naas_python as naas"
]
},
{
@@ -121,29 +111,29 @@
"tags": []
},
"source": [
- "### Setup Variables\n",
+ "### Setup variables\n",
"- `github_token`: personal token creates\n",
"- `issue_url`: link to the chosen issue"
]
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 23,
"id": "01647a55",
"metadata": {
"execution": {
- "iopub.execute_input": "2024-06-05T12:26:02.800457Z",
- "iopub.status.busy": "2024-06-05T12:26:02.800186Z",
- "iopub.status.idle": "2024-06-05T12:26:02.804857Z",
- "shell.execute_reply": "2024-06-05T12:26:02.804318Z",
- "shell.execute_reply.started": "2024-06-05T12:26:02.800432Z"
+ "iopub.execute_input": "2024-06-06T12:46:33.132172Z",
+ "iopub.status.busy": "2024-06-06T12:46:33.131874Z",
+ "iopub.status.idle": "2024-06-06T12:46:34.326369Z",
+ "shell.execute_reply": "2024-06-06T12:46:34.325734Z",
+ "shell.execute_reply.started": "2024-06-06T12:46:33.132140Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
- "github_token = \"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\"\n",
+ "github_token = naas.secret.get(\"GITHUB_TOKEN\").value\n",
"issue_url = \"https://github.com/pola-rs/polars/issues/16661\""
]
},
@@ -155,20 +145,21 @@
"tags": []
},
"source": [
- "## Model\n"
+ "## Model\n",
+ "### Get comments and reactions from issue"
]
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 24,
"id": "29e87112-879c-439c-87b3-3065f9a91085",
"metadata": {
"execution": {
- "iopub.execute_input": "2024-06-05T12:26:05.445237Z",
- "iopub.status.busy": "2024-06-05T12:26:05.444998Z",
- "iopub.status.idle": "2024-06-05T12:26:05.452150Z",
- "shell.execute_reply": "2024-06-05T12:26:05.451507Z",
- "shell.execute_reply.started": "2024-06-05T12:26:05.445212Z"
+ "iopub.execute_input": "2024-06-06T12:46:34.327546Z",
+ "iopub.status.busy": "2024-06-06T12:46:34.327369Z",
+ "iopub.status.idle": "2024-06-06T12:46:34.335484Z",
+ "shell.execute_reply": "2024-06-06T12:46:34.334966Z",
+ "shell.execute_reply.started": "2024-06-06T12:46:34.327526Z"
},
"tags": []
},
@@ -221,20 +212,21 @@
"tags": []
},
"source": [
- "## Output\n"
+ "## Output\n",
+ "### Display result"
]
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 25,
"id": "947ce69b-f636-4ac4-abd9-4254fca3f897",
"metadata": {
"execution": {
- "iopub.execute_input": "2024-06-05T12:29:18.324360Z",
- "iopub.status.busy": "2024-06-05T12:29:18.324086Z",
- "iopub.status.idle": "2024-06-05T12:29:18.786161Z",
- "shell.execute_reply": "2024-06-05T12:29:18.785121Z",
- "shell.execute_reply.started": "2024-06-05T12:29:18.324334Z"
+ "iopub.execute_input": "2024-06-06T12:46:34.337044Z",
+ "iopub.status.busy": "2024-06-06T12:46:34.336812Z",
+ "iopub.status.idle": "2024-06-06T12:46:34.904718Z",
+ "shell.execute_reply": "2024-06-06T12:46:34.904094Z",
+ "shell.execute_reply.started": "2024-06-06T12:46:34.337017Z"
},
"tags": []
},
@@ -260,41 +252,72 @@
" \n",
" \n",
" | \n",
- " COMMENT_ID | \n",
+ " OBJECT_URL | \n",
+ " ID | \n",
+ " TYPE | \n",
" CONTENT | \n",
- " DATE/TIME | \n",
- " CREATOR NAME | \n",
- " CREATOR LOGIN | \n",
+ " DATE_TIME | \n",
+ " USER_NAME | \n",
+ " USER_LOGIN | \n",
" USER_ID | \n",
- " REACTIONS COUNT | \n",
- " REACTION TYPE | \n",
"
\n",
" \n",
"
\n",
" \n",
" 0 | \n",
+ " https://api.github.com/repos/pola-rs/polars/is... | \n",
" 2144455441 | \n",
+ " COMMENT | \n",
" We can support both. Coming up. | \n",
" 2024-06-03T07:20:29Z | \n",
" N/A | \n",
" ritchie46 | \n",
" 3023000 | \n",
- " 2 | \n",
- " {'hooray': 1, '+1': 1} | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " https://api.github.com/repos/pola-rs/polars/is... | \n",
+ " 2144455441 | \n",
+ " REACTION | \n",
+ " hooray | \n",
+ " 2024-06-03T07:25:35Z | \n",
+ " N/A | \n",
+ " alexander-beedie | \n",
+ " 2613171 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " https://api.github.com/repos/pola-rs/polars/is... | \n",
+ " 2144455441 | \n",
+ " REACTION | \n",
+ " +1 | \n",
+ " 2024-06-03T10:26:28Z | \n",
+ " N/A | \n",
+ " cmdlineluser | \n",
+ " 99486669 | \n",
"
\n",
" \n",
"\n",
""
],
"text/plain": [
- " COMMENT_ID CONTENT DATE/TIME \\\n",
- "0 2144455441 We can support both. Coming up. 2024-06-03T07:20:29Z \n",
+ " OBJECT_URL ID TYPE \\\n",
+ "0 https://api.github.com/repos/pola-rs/polars/is... 2144455441 COMMENT \n",
+ "1 https://api.github.com/repos/pola-rs/polars/is... 2144455441 REACTION \n",
+ "2 https://api.github.com/repos/pola-rs/polars/is... 2144455441 REACTION \n",
+ "\n",
+ " CONTENT DATE_TIME USER_NAME \\\n",
+ "0 We can support both. Coming up. 2024-06-03T07:20:29Z N/A \n",
+ "1 hooray 2024-06-03T07:25:35Z N/A \n",
+ "2 +1 2024-06-03T10:26:28Z N/A \n",
"\n",
- " CREATOR NAME CREATOR LOGIN USER_ID REACTIONS COUNT REACTION TYPE \n",
- "0 N/A ritchie46 3023000 2 {'hooray': 1, '+1': 1} "
+ " USER_LOGIN USER_ID \n",
+ "0 ritchie46 3023000 \n",
+ "1 alexander-beedie 2613171 \n",
+ "2 cmdlineluser 99486669 "
]
},
- "execution_count": 9,
+ "execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
@@ -307,32 +330,45 @@
" comments = get_issue_comments(repo_owner, repo_name, issue_number)\n",
"\n",
" for comment in comments:\n",
+ " object_url = comment['issue_url']\n",
" comment_id = comment['id']\n",
" comment_body = comment['body']\n",
" comment_created_at = comment['created_at']\n",
- " user_id = comment['user']['id']\n",
" comment_user_name = comment['user']['name'] if 'name' in comment['user'] else 'N/A'\n",
" comment_user_login = comment['user']['login']\n",
+ " comment_user_id = comment['user']['id']\n",
+ " \n",
+ " data = [{\n",
+ " \"OBJECT_URL\": object_url,\n",
+ " \"ID\": comment_id,\n",
+ " \"TYPE\": \"COMMENT\",\n",
+ " \"CONTENT\": comment_body,\n",
+ " \"DATE_TIME\": comment_created_at,\n",
+ " \"USER_NAME\": comment_user_name,\n",
+ " \"USER_LOGIN\": comment_user_login,\n",
+ " \"USER_ID\": comment_user_id,\n",
+ " }]\n",
+ " \n",
" reactions = get_comment_reactions(repo_owner, repo_name, comment_id)\n",
- " reaction_count = len(reactions)\n",
- " reaction_types = {}\n",
" for reaction in reactions:\n",
- " reaction_content = reaction['content']\n",
- " if reaction_content in reaction_types:\n",
- " reaction_types[reaction_content] += 1\n",
- " else:\n",
- " reaction_types[reaction_content] = 1\n",
- "\n",
- " data.append({\n",
- " \"COMMENT_ID\": comment_id,\n",
- " \"CONTENT\": comment_body,\n",
- " \"DATE/TIME\": comment_created_at,\n",
- " \"CREATOR NAME\": comment_user_name,\n",
- " \"CREATOR LOGIN\": comment_user_login,\n",
- " \"USER_ID\": user_id,\n",
- " \"REACTIONS COUNT\": reaction_count,\n",
- " \"REACTION TYPE\": reaction_types\n",
- " })\n",
+ " reaction_id = reaction['id']\n",
+ " reaction_body = reaction['content']\n",
+ " reaction_created_at = reaction['created_at']\n",
+ " reaction_user_name = reaction['user']['name'] if 'name' in comment['user'] else 'N/A'\n",
+ " reaction_user_login = reaction['user']['login']\n",
+ " reaction_user_id = reaction['user']['id']\n",
+ " \n",
+ " data.append({\n",
+ " \"OBJECT_URL\": object_url,\n",
+ " \"ID\": comment_id,\n",
+ " \"TYPE\": \"REACTION\",\n",
+ " \"CONTENT\": reaction_body,\n",
+ " \"DATE_TIME\": reaction_created_at,\n",
+ " \"USER_NAME\": reaction_user_name,\n",
+ " \"USER_LOGIN\": reaction_user_login,\n",
+ " \"USER_ID\": reaction_user_id,\n",
+ " })\n",
+ " \n",
" \n",
"\n",
"except ValueError as e:\n",
@@ -341,6 +377,14 @@
"df = pd.DataFrame(data)\n",
"df"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "5326f466-a95b-467a-8b8e-30235d6e5a78",
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {
diff --git a/GitHub/GitHub_Get_comments_from_issue.ipynb b/GitHub/GitHub_Get_comments_from_issue.ipynb
index 59790bcd73..2ccf8c9c97 100644
--- a/GitHub/GitHub_Get_comments_from_issue.ipynb
+++ b/GitHub/GitHub_Get_comments_from_issue.ipynb
@@ -31,7 +31,7 @@
"tags": []
},
"source": [
- "**Tags:** #github #notion #comments #issue #automation"
+ "**Tags:** #github #comments #issue #automation #snippet"
]
},
{
@@ -53,7 +53,7 @@
"tags": []
},
"source": [
- "**Last update:** 2024-06-5 (Created: 2024-06-4)"
+ "**Last update:** 2024-06-05 (Created: 2024-06-04)"
]
},
{
@@ -93,15 +93,15 @@
},
{
"cell_type": "code",
- "execution_count": 29,
+ "execution_count": 1,
"id": "353ef79c",
"metadata": {
"execution": {
- "iopub.execute_input": "2024-06-05T12:26:24.237880Z",
- "iopub.status.busy": "2024-06-05T12:26:24.237644Z",
- "iopub.status.idle": "2024-06-05T12:26:24.240756Z",
- "shell.execute_reply": "2024-06-05T12:26:24.240038Z",
- "shell.execute_reply.started": "2024-06-05T12:26:24.237857Z"
+ "iopub.execute_input": "2024-06-06T12:39:11.746534Z",
+ "iopub.status.busy": "2024-06-06T12:39:11.746221Z",
+ "iopub.status.idle": "2024-06-06T12:39:12.469289Z",
+ "shell.execute_reply": "2024-06-06T12:39:12.468657Z",
+ "shell.execute_reply.started": "2024-06-06T12:39:11.746460Z"
},
"papermill": {},
"tags": []
@@ -110,7 +110,8 @@
"source": [
"import requests\n",
"import re\n",
- "import pandas as pd"
+ "import pandas as pd\n",
+ "import naas_python as naas"
]
},
{
@@ -128,22 +129,22 @@
},
{
"cell_type": "code",
- "execution_count": 30,
+ "execution_count": 2,
"id": "01647a55",
"metadata": {
"execution": {
- "iopub.execute_input": "2024-06-05T12:26:24.544846Z",
- "iopub.status.busy": "2024-06-05T12:26:24.544280Z",
- "iopub.status.idle": "2024-06-05T12:26:24.571902Z",
- "shell.execute_reply": "2024-06-05T12:26:24.571365Z",
- "shell.execute_reply.started": "2024-06-05T12:26:24.544812Z"
+ "iopub.execute_input": "2024-06-06T12:39:13.772063Z",
+ "iopub.status.busy": "2024-06-06T12:39:13.771758Z",
+ "iopub.status.idle": "2024-06-06T12:39:15.831436Z",
+ "shell.execute_reply": "2024-06-06T12:39:15.830739Z",
+ "shell.execute_reply.started": "2024-06-06T12:39:13.772031Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
- "github_token = \"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\"\n",
+ "github_token = naas.secret.get(\"GITHUB_TOKEN\").value\n",
"issue_url = \"https://github.com/pola-rs/polars/issues/16661\""
]
},
@@ -158,21 +159,77 @@
"## Model\n"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "2027bb2d-b721-4d6e-97ea-c3e5d1b4ea4d",
+ "metadata": {},
+ "source": [
+ "### Get issues comments"
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 31,
+ "execution_count": 3,
"id": "29e87112-879c-439c-87b3-3065f9a91085",
"metadata": {
"execution": {
- "iopub.execute_input": "2024-06-05T12:26:24.854242Z",
- "iopub.status.busy": "2024-06-05T12:26:24.853990Z",
- "iopub.status.idle": "2024-06-05T12:26:24.860484Z",
- "shell.execute_reply": "2024-06-05T12:26:24.859791Z",
- "shell.execute_reply.started": "2024-06-05T12:26:24.854218Z"
+ "iopub.execute_input": "2024-06-06T12:39:15.832732Z",
+ "iopub.status.busy": "2024-06-06T12:39:15.832548Z",
+ "iopub.status.idle": "2024-06-06T12:39:16.075611Z",
+ "shell.execute_reply": "2024-06-06T12:39:16.074933Z",
+ "shell.execute_reply.started": "2024-06-06T12:39:15.832711Z"
},
"tags": []
},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[{'url': 'https://api.github.com/repos/pola-rs/polars/issues/comments/2144455441',\n",
+ " 'html_url': 'https://github.com/pola-rs/polars/issues/16661#issuecomment-2144455441',\n",
+ " 'issue_url': 'https://api.github.com/repos/pola-rs/polars/issues/16661',\n",
+ " 'id': 2144455441,\n",
+ " 'node_id': 'IC_kwDOD7gq785_0csR',\n",
+ " 'user': {'login': 'ritchie46',\n",
+ " 'id': 3023000,\n",
+ " 'node_id': 'MDQ6VXNlcjMwMjMwMDA=',\n",
+ " 'avatar_url': 'https://avatars.githubusercontent.com/u/3023000?v=4',\n",
+ " 'gravatar_id': '',\n",
+ " 'url': 'https://api.github.com/users/ritchie46',\n",
+ " 'html_url': 'https://github.com/ritchie46',\n",
+ " 'followers_url': 'https://api.github.com/users/ritchie46/followers',\n",
+ " 'following_url': 'https://api.github.com/users/ritchie46/following{/other_user}',\n",
+ " 'gists_url': 'https://api.github.com/users/ritchie46/gists{/gist_id}',\n",
+ " 'starred_url': 'https://api.github.com/users/ritchie46/starred{/owner}{/repo}',\n",
+ " 'subscriptions_url': 'https://api.github.com/users/ritchie46/subscriptions',\n",
+ " 'organizations_url': 'https://api.github.com/users/ritchie46/orgs',\n",
+ " 'repos_url': 'https://api.github.com/users/ritchie46/repos',\n",
+ " 'events_url': 'https://api.github.com/users/ritchie46/events{/privacy}',\n",
+ " 'received_events_url': 'https://api.github.com/users/ritchie46/received_events',\n",
+ " 'type': 'User',\n",
+ " 'site_admin': False},\n",
+ " 'created_at': '2024-06-03T07:20:29Z',\n",
+ " 'updated_at': '2024-06-03T07:20:29Z',\n",
+ " 'author_association': 'MEMBER',\n",
+ " 'body': 'We can support both. Coming up.',\n",
+ " 'reactions': {'url': 'https://api.github.com/repos/pola-rs/polars/issues/comments/2144455441/reactions',\n",
+ " 'total_count': 2,\n",
+ " '+1': 1,\n",
+ " '-1': 0,\n",
+ " 'laugh': 0,\n",
+ " 'hooray': 1,\n",
+ " 'confused': 0,\n",
+ " 'heart': 0,\n",
+ " 'rocket': 0,\n",
+ " 'eyes': 0},\n",
+ " 'performed_via_github_app': None}]"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"def extract_repo_details(issue_url):\n",
" # Extract owner, repo name, and issue number from the issue URL\n",
@@ -181,7 +238,10 @@
" raise ValueError(\"Invalid issue URL\")\n",
" return match.group('owner'), match.group('repo'), match.group('number')\n",
"\n",
- "def get_issue_comments(repo_owner, repo_name, issue_number):\n",
+ "def get_issue_comments(issue_url):\n",
+ " # Extract repo details\n",
+ " repo_owner, repo_name, issue_number = extract_repo_details(issue_url)\n",
+ " \n",
" # GitHub API URL to get issue comments\n",
" api_url = f\"https://api.github.com/repos/{repo_owner}/{repo_name}/issues/{issue_number}/comments\"\n",
" headers = {\n",
@@ -196,21 +256,8 @@
" else:\n",
" print(f\"Failed to fetch comments: {response.status_code}\")\n",
" return []\n",
- "\n",
- "def get_comment_reactions(repo_owner, repo_name, comment_id):\n",
- " api_url = f\"https://api.github.com/repos/{repo_owner}/{repo_name}/issues/comments/{comment_id}/reactions\"\n",
- " headers = {\n",
- " 'Authorization': f'token {github_token}',\n",
- " 'Accept': 'application/vnd.github.squirrel-girl-preview+json' # Required for reactions API\n",
- " }\n",
- "\n",
- " response = requests.get(api_url, headers=headers)\n",
- "\n",
- " if response.status_code == 200:\n",
- " return response.json()\n",
- " else:\n",
- " print(f\"Failed to fetch reactions for comment {comment_id}: {response.status_code}\")\n",
- " return []"
+ " \n",
+ "comments = get_issue_comments(issue_url)"
]
},
{
@@ -224,17 +271,25 @@
"## Output\n"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "0bfe3031-0b86-47db-b47d-7510df4610a7",
+ "metadata": {},
+ "source": [
+ "### Display result"
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 33,
+ "execution_count": 4,
"id": "947ce69b-f636-4ac4-abd9-4254fca3f897",
"metadata": {
"execution": {
- "iopub.execute_input": "2024-06-05T12:29:35.487013Z",
- "iopub.status.busy": "2024-06-05T12:29:35.486782Z",
- "iopub.status.idle": "2024-06-05T12:29:35.926057Z",
- "shell.execute_reply": "2024-06-05T12:29:35.925321Z",
- "shell.execute_reply.started": "2024-06-05T12:29:35.486991Z"
+ "iopub.execute_input": "2024-06-06T12:39:18.512884Z",
+ "iopub.status.busy": "2024-06-06T12:39:18.512647Z",
+ "iopub.status.idle": "2024-06-06T12:39:18.527890Z",
+ "shell.execute_reply": "2024-06-06T12:39:18.527333Z",
+ "shell.execute_reply.started": "2024-06-06T12:39:18.512860Z"
},
"tags": []
},
@@ -262,11 +317,11 @@
" | \n",
" COMMENT_ID | \n",
" CONTENT | \n",
- " DATE/TIME | \n",
- " CREATOR NAME | \n",
- " CREATOR LOGIN | \n",
+ " DATE_TIME | \n",
+ " CREATOR_NAME | \n",
+ " CREATOR_LOGIN | \n",
" USER_ID | \n",
- " REACTIONS COUNT | \n",
+ " REACTIONS_COUNT | \n",
" \n",
" \n",
" \n",
@@ -285,25 +340,21 @@
""
],
"text/plain": [
- " COMMENT_ID CONTENT DATE/TIME \\\n",
+ " COMMENT_ID CONTENT DATE_TIME \\\n",
"0 2144455441 We can support both. Coming up. 2024-06-03T07:20:29Z \n",
"\n",
- " CREATOR NAME CREATOR LOGIN USER_ID REACTIONS COUNT \n",
+ " CREATOR_NAME CREATOR_LOGIN USER_ID REACTIONS_COUNT \n",
"0 N/A ritchie46 3023000 2 "
]
},
- "execution_count": 33,
+ "execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = []\n",
- "\n",
- "try:\n",
- " repo_owner, repo_name, issue_number = extract_repo_details(issue_url)\n",
- " comments = get_issue_comments(repo_owner, repo_name, issue_number)\n",
- "\n",
+ "if len(comments) > 0:\n",
" for comment in comments:\n",
" comment_id = comment['id']\n",
" comment_body = comment['body']\n",
@@ -311,26 +362,28 @@
" user_id = comment['user']['id']\n",
" comment_user_name = comment['user']['name'] if 'name' in comment['user'] else 'N/A'\n",
" comment_user_login = comment['user']['login']\n",
- " reactions = get_comment_reactions(repo_owner, repo_name, comment_id)\n",
- " reaction_count = len(reactions)\n",
+ " reaction_count = comment['reactions']['total_count']\n",
"\n",
" data.append({\n",
" \"COMMENT_ID\": comment_id,\n",
" \"CONTENT\": comment_body,\n",
- " \"DATE/TIME\": comment_created_at,\n",
- " \"CREATOR NAME\": comment_user_name,\n",
- " \"CREATOR LOGIN\": comment_user_login,\n",
+ " \"DATE_TIME\": comment_created_at,\n",
+ " \"CREATOR_NAME\": comment_user_name,\n",
+ " \"CREATOR_LOGIN\": comment_user_login,\n",
" \"USER_ID\": user_id,\n",
- " \"REACTIONS COUNT\": reaction_count\n",
- " })\n",
- " \n",
- "\n",
- "except ValueError as e:\n",
- " print(e)\n",
- " \n",
+ " \"REACTIONS_COUNT\": reaction_count\n",
+ " }) \n",
"df = pd.DataFrame(data)\n",
"df"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "74e065d6-9c08-4860-afa4-a777719fcbd0",
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {
diff --git a/GitHub/GitHub_Get_reactions_from_comment.ipynb b/GitHub/GitHub_Get_reactions_from_comment.ipynb
index a92ce53674..206d089429 100644
--- a/GitHub/GitHub_Get_reactions_from_comment.ipynb
+++ b/GitHub/GitHub_Get_reactions_from_comment.ipynb
@@ -31,7 +31,7 @@
"tags": []
},
"source": [
- "**Tags:** #github #notion #reactions #automation"
+ "**Tags:** #github #reactions #automation #snippet"
]
},
{
@@ -53,7 +53,7 @@
"tags": []
},
"source": [
- "**Last update:** 2024-06-5 (Created: 2024-06-4)"
+ "**Last update:** 2024-06-05 (Created: 2024-06-04)"
]
},
{
@@ -97,11 +97,11 @@
"id": "353ef79c",
"metadata": {
"execution": {
- "iopub.execute_input": "2024-06-05T13:51:33.951703Z",
- "iopub.status.busy": "2024-06-05T13:51:33.951349Z",
- "iopub.status.idle": "2024-06-05T13:51:34.871650Z",
- "shell.execute_reply": "2024-06-05T13:51:34.871034Z",
- "shell.execute_reply.started": "2024-06-05T13:51:33.951615Z"
+ "iopub.execute_input": "2024-06-06T12:38:24.837677Z",
+ "iopub.status.busy": "2024-06-06T12:38:24.837416Z",
+ "iopub.status.idle": "2024-06-06T12:38:25.527645Z",
+ "shell.execute_reply": "2024-06-06T12:38:25.527048Z",
+ "shell.execute_reply.started": "2024-06-06T12:38:24.837614Z"
},
"papermill": {},
"tags": []
@@ -109,7 +109,8 @@
"outputs": [],
"source": [
"import requests\n",
- "import pandas as pd"
+ "import pandas as pd\n",
+ "import naas_python as naas"
]
},
{
@@ -120,7 +121,7 @@
"tags": []
},
"source": [
- "### Setup Variables\n",
+ "### Setup variables\n",
"- `github_token`: personal token creates\n",
"- `reaction_url`: link to the comments reaction data"
]
@@ -131,18 +132,18 @@
"id": "01647a55",
"metadata": {
"execution": {
- "iopub.execute_input": "2024-06-05T13:51:34.872994Z",
- "iopub.status.busy": "2024-06-05T13:51:34.872769Z",
- "iopub.status.idle": "2024-06-05T13:51:34.877669Z",
- "shell.execute_reply": "2024-06-05T13:51:34.877150Z",
- "shell.execute_reply.started": "2024-06-05T13:51:34.872965Z"
+ "iopub.execute_input": "2024-06-06T12:38:25.663519Z",
+ "iopub.status.busy": "2024-06-06T12:38:25.663253Z",
+ "iopub.status.idle": "2024-06-06T12:38:27.786503Z",
+ "shell.execute_reply": "2024-06-06T12:38:27.785891Z",
+ "shell.execute_reply.started": "2024-06-06T12:38:25.663489Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
- "github_token = \"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\"\n",
+ "github_token = naas.secret.get(\"GITHUB_TOKEN\").value\n",
"reactions_url = \"https://api.github.com/repos/pola-rs/polars/issues/comments/2144455441/reactions\""
]
},
@@ -157,21 +158,37 @@
"## Model\n"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "a3e91a67-b462-4dcc-a049-a8d68941f2df",
+ "metadata": {},
+ "source": [
+ "### Get comment reactions"
+ ]
+ },
{
"cell_type": "code",
"execution_count": 3,
"id": "29e87112-879c-439c-87b3-3065f9a91085",
"metadata": {
"execution": {
- "iopub.execute_input": "2024-06-05T13:51:36.588687Z",
- "iopub.status.busy": "2024-06-05T13:51:36.588455Z",
- "iopub.status.idle": "2024-06-05T13:51:36.595579Z",
- "shell.execute_reply": "2024-06-05T13:51:36.594904Z",
- "shell.execute_reply.started": "2024-06-05T13:51:36.588665Z"
+ "iopub.execute_input": "2024-06-06T12:38:27.787815Z",
+ "iopub.status.busy": "2024-06-06T12:38:27.787595Z",
+ "iopub.status.idle": "2024-06-06T12:38:28.019522Z",
+ "shell.execute_reply": "2024-06-06T12:38:28.018828Z",
+ "shell.execute_reply.started": "2024-06-06T12:38:27.787785Z"
},
"tags": []
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Requesting: https://api.github.com/repos/pola-rs/polars/issues/comments/2144455441/reactions\n"
+ ]
+ }
+ ],
"source": [
"def get_comment_reactions(reactions_url):\n",
" headers = {\n",
@@ -187,36 +204,8 @@
" else:\n",
" print(f\"Failed to fetch reactions: {response.status_code} - {response.text}\")\n",
" return []\n",
- "\n",
- "def print_reaction_types_table(reactions_url):\n",
- " reactions = get_comment_reactions(reactions_url)\n",
- "\n",
- " if reactions:\n",
- " reaction_types = {\n",
- " '+1': 0,\n",
- " '-1': 0,\n",
- " 'laugh': 0,\n",
- " 'hooray': 0,\n",
- " 'confused': 0,\n",
- " 'heart': 0,\n",
- " 'rocket': 0,\n",
- " 'eyes': 0\n",
- " }\n",
- " \n",
- " for reaction in reactions:\n",
- " reaction_content = reaction['content']\n",
- " if reaction_content in reaction_types:\n",
- " reaction_types[reaction_content] += 1\n",
- "\n",
- " # Convert the reaction types to a DataFrame\n",
- " reaction_data = pd.DataFrame(list(reaction_types.items()), columns=['Reaction Type', 'Count'])\n",
- " \n",
- " # Filter out reactions with a count of 0\n",
- " filtered_reaction_data = reaction_data[reaction_data['Count'] > 0]\n",
- " \n",
- " print(filtered_reaction_data)\n",
- " else:\n",
- " print(\"No reactions found or failed to fetch reactions.\")\n"
+ " \n",
+ "reactions = get_comment_reactions(reactions_url)"
]
},
{
@@ -230,17 +219,25 @@
"## Output\n"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "8b6ecf57-fec4-4e72-a7b8-4985bca76c05",
+ "metadata": {},
+ "source": [
+ "### Display result"
+ ]
+ },
{
"cell_type": "code",
"execution_count": 4,
"id": "947ce69b-f636-4ac4-abd9-4254fca3f897",
"metadata": {
"execution": {
- "iopub.execute_input": "2024-06-05T13:51:38.846563Z",
- "iopub.status.busy": "2024-06-05T13:51:38.846336Z",
- "iopub.status.idle": "2024-06-05T13:51:39.098365Z",
- "shell.execute_reply": "2024-06-05T13:51:39.097800Z",
- "shell.execute_reply.started": "2024-06-05T13:51:38.846541Z"
+ "iopub.execute_input": "2024-06-06T12:38:30.189199Z",
+ "iopub.status.busy": "2024-06-06T12:38:30.188660Z",
+ "iopub.status.idle": "2024-06-06T12:38:30.205579Z",
+ "shell.execute_reply": "2024-06-06T12:38:30.204858Z",
+ "shell.execute_reply.started": "2024-06-06T12:38:30.189162Z"
},
"tags": []
},
@@ -249,7 +246,6 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Requesting: https://api.github.com/repos/pola-rs/polars/issues/comments/2144455441/reactions\n",
" Reaction Type Count\n",
"0 +1 1\n",
"3 hooray 1\n"
@@ -257,7 +253,35 @@
}
],
"source": [
- "print_reaction_types_table(reactions_url)"
+ "def print_reaction_types_table(reactions):\n",
+ " if reactions:\n",
+ " reaction_types = {\n",
+ " '+1': 0,\n",
+ " '-1': 0,\n",
+ " 'laugh': 0,\n",
+ " 'hooray': 0,\n",
+ " 'confused': 0,\n",
+ " 'heart': 0,\n",
+ " 'rocket': 0,\n",
+ " 'eyes': 0\n",
+ " }\n",
+ " \n",
+ " for reaction in reactions:\n",
+ " reaction_content = reaction['content']\n",
+ " if reaction_content in reaction_types:\n",
+ " reaction_types[reaction_content] += 1\n",
+ "\n",
+ " # Convert the reaction types to a DataFrame\n",
+ " reaction_data = pd.DataFrame(list(reaction_types.items()), columns=['Reaction Type', 'Count'])\n",
+ " \n",
+ " # Filter out reactions with a count of 0\n",
+ " filtered_reaction_data = reaction_data[reaction_data['Count'] > 0]\n",
+ " \n",
+ " print(filtered_reaction_data)\n",
+ " else:\n",
+ " print(\"No reactions found or failed to fetch reactions.\")\n",
+ " \n",
+ "print_reaction_types_table(reactions)"
]
},
{