From 2e589aa7abe134d3ab03bcb75012397aa2fd85e9 Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Mon, 20 Nov 2023 22:02:22 +0100 Subject: [PATCH] feat: update buffer templates + add connection template --- Buffer/Buffer_Create_draft.ipynb | 6 +- Buffer/Buffer_Send_text_to_Idea.ipynb | 6 +- Buffer/Buffer_Setup_connection.ipynb | 278 ++++++++++++++++++++++++++ 3 files changed, 284 insertions(+), 6 deletions(-) create mode 100644 Buffer/Buffer_Setup_connection.ipynb diff --git a/Buffer/Buffer_Create_draft.ipynb b/Buffer/Buffer_Create_draft.ipynb index 606a12b24c..b6460f8807 100644 --- a/Buffer/Buffer_Create_draft.ipynb +++ b/Buffer/Buffer_Create_draft.ipynb @@ -126,7 +126,7 @@ "### Setup variables\n", "- `buffer_url`: This variable holds the URL of the specific Buffer profile where you want to create a new post. Example: \"https://publish.buffer.com/profile/xxxxxxxxxxx/tab/queue\"\n", "- `text`: This variable contains the text content that you want to post on the Buffer profile. You can modify this string to change the content of the post.\n", - "- `cookie`: This variable is used to store the cookie information from your Buffer session. The `input()` function is used to prompt you to manually enter your cookie information. You need to inspect your Buffer session in your web browser and copy/paste your cookie into the prompt. The cookie is used for authentication and maintaining the session with Buffer." + "- `cookie`: This variable is used to store the cookie information from your Buffer session." ] }, { @@ -141,7 +141,7 @@ "source": [ "buffer_url = \"https://publish.buffer.com/profile/xxxxxxxxxxxxxx/tab/queue\"\n", "text = \"My Draft\"\n", - "cookie = input(\"Inspect your Buffer and Copy/Paste your cookie:\")" + "cookie = naas.secret.get(\"BUFFER_COOKIES\") or \"Inspect your Buffer and Copy/Paste your cookie\"" ] }, { @@ -314,4 +314,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/Buffer/Buffer_Send_text_to_Idea.ipynb b/Buffer/Buffer_Send_text_to_Idea.ipynb index c1f651efa6..f087ea7158 100644 --- a/Buffer/Buffer_Send_text_to_Idea.ipynb +++ b/Buffer/Buffer_Send_text_to_Idea.ipynb @@ -126,7 +126,7 @@ "### Setup variables\n", "- `buffer_url`: This variable holds the URL of the specific Buffer profile where you want to create a new post. Example: \"https://publish.buffer.com/profile/xxxxxxxxxxx/tab/queue\"\n", "- `text`: This variable contains the text content that you want to post on the Buffer profile. You can modify this string to change the content of the post.\n", - "- `cookie`: This variable is used to store the cookie information from your Buffer session. The `input()` function is used to prompt you to manually enter your cookie information. You need to inspect your Buffer session in your web browser and copy/paste your cookie into the prompt. The cookie is used for authentication and maintaining the session with Buffer." + "- `cookie`: This variable is used to store the cookie information from your Buffer session." ] }, { @@ -141,7 +141,7 @@ "source": [ "organization_id = \"xxxxxxx\"\n", "text = \"My Buffer Idea\"\n", - "cookie = input(\"Inspect your Buffer and Copy/Paste your cookie:\")" + "cookie = naas.secret.get(\"BUFFER_COOKIES\") or \"Inspect your Buffer and Copy/Paste your cookie\"" ] }, { @@ -323,4 +323,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/Buffer/Buffer_Setup_connection.ipynb b/Buffer/Buffer_Setup_connection.ipynb new file mode 100644 index 0000000000..dfefdec7d6 --- /dev/null +++ b/Buffer/Buffer_Setup_connection.ipynb @@ -0,0 +1,278 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "02b78a46-e367-48fb-9468-d560000cc994", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Buffer.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "a5b2c509-2c29-49e8-af91-4f3f1e386da3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Buffer - Setup connection" + ] + }, + { + "cell_type": "markdown", + "id": "d77fe283-4edd-42d3-a909-8e207d4b842f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #buffer #naas #secret #connection #setup" + ] + }, + { + "cell_type": "markdown", + "id": "b90f2d91-c886-4e36-8265-b09d06bb1c7f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel)" + ] + }, + { + "cell_type": "markdown", + "id": "6bbf7807-dda4-4b8a-b016-fe258a0fa33f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-11-20 (Created: 2023-11-20)" + ] + }, + { + "cell_type": "markdown", + "id": "214749fe-7f0b-4755-b7ea-1d200c234cc6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook help you setup your connection with Buffer and add required credentials to Naas secret. You will be able to establish a seamless connection to Buffer without the need to repeatedly redefine your credentials in variables by using `naas.secret.get()` in your notebook." + ] + }, + { + "cell_type": "markdown", + "id": "a1329bea-ad80-4981-874c-8776b11f89a8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n", + "- [Generate a personal access token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token)\n", + "- [Naas Secret Documentation](https://site.naas.ai/docs/developers/jobs/secret)" + ] + }, + { + "cell_type": "markdown", + "id": "cff349c8-2816-4ae4-9229-027c068eeb51", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "80266a9e-fe54-4f3e-aeb2-01483bbc53f9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cc038b10-2679-42bc-909e-09a298339df4", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import naas" + ] + }, + { + "cell_type": "markdown", + "id": "30127040-e487-4115-8317-5084823b3a6f", + "metadata": { + "papermill": {}, + "tags": [ + "variables" + ] + }, + "source": [ + "### Setup variables\n", + "**Pre-requisite**\n", + "\n", + "You need to inspect your Buffer session in your web browser and copy/paste your cookie in the variable below. The cookie will be used for authentication and maintaining the session with Buffer.\n", + "\n", + "**Mandatory**\n", + "- `buffer_cookies`: This variable is used to store the cookie information from your Buffer session. This value will be stored under the secret 'BUFFER_COOKIES'.\n", + "\n", + "**Optional**\n", + "- `secrets`: Dict to add secrets to naas" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8d86b8fb-2576-426d-a305-50043c24c23e", + "metadata": { + "papermill": {}, + "tags": [ + "parameters" + ] + }, + "outputs": [], + "source": [ + "# Mandatory\n", + "buffer_cookies = None\n", + "\n", + "# Optional\n", + "secrets = {\n", + " \"BUFFER_COOKIES\": buffer_cookies,\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "1b0ae044-cac2-479f-b1fc-a3318696adf5", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "3aadae7f-fbe5-4f97-a6a9-6efe9dd1a42f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Add secret" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e235794a-6907-4f0e-ab2b-5aa6668a8d3b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "for secret in secrets:\n", + " new_value = secrets.get(secret)\n", + " if new_value:\n", + " naas.secret.add(secret, secrets.get(secret))" + ] + }, + { + "cell_type": "markdown", + "id": "7c97931b-4ce8-46f9-a70c-45393c5669ee", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "760ec150-d79a-4208-adfe-d0336d443dc8", + "metadata": {}, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4005faa2-a781-4805-9c08-74951e900d12", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "df = naas.secret.list()\n", + "df = df[df[\"name\"].isin(secrets.keys())]\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3cb18d4d-cd69-49b5-92ea-4b638885e652", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "naas": { + "notebook_id": "cc22b3eb0484bf2a314634076226daee8a2a74e35de569fa2fbd40dae558222c", + "notebook_path": "GitHub/GitHub_Connect_from_Naas_Chat.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.4.0" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}