From f418bd561470472b271095a891be0b82a37ca484 Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Mon, 9 Oct 2023 09:21:30 +0200 Subject: [PATCH 1/8] feat(Medium): Add Publish article from Mardown file --- ...um_Publish_article_from_Mardown_file.ipynb | 241 ++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 Medium/Medium_Publish_article_from_Mardown_file.ipynb diff --git a/Medium/Medium_Publish_article_from_Mardown_file.ipynb b/Medium/Medium_Publish_article_from_Mardown_file.ipynb new file mode 100644 index 0000000000..58a2269cf5 --- /dev/null +++ b/Medium/Medium_Publish_article_from_Mardown_file.ipynb @@ -0,0 +1,241 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "b2986071-1a29-4f66-995e-72565d384ce8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas\"" + ] + }, + { + "cell_type": "markdown", + "id": "5d7b0c0b-5e6c-4be3-b901-704fc00b6c08", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Medium - Publish article from Mardown file" + ] + }, + { + "cell_type": "markdown", + "id": "ba4944a7-f4e5-4e89-9e3e-b4ee2e12c15f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #medium #publish #article #markdown #file #api" + ] + }, + { + "cell_type": "markdown", + "id": "c96fc2a3-0910-4b6d-a735-1e83cd5fa24e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Firstname Lastname]()" + ] + }, + { + "cell_type": "markdown", + "id": "edcf9f6c-c073-46c4-92ab-cc72866daf37", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-10-09 (Created: 2023-10-09)" + ] + }, + { + "cell_type": "markdown", + "id": "9b1586dd-d9e8-4f75-a583-c5cd5952bb05", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook explains how to publish an article from a Markdown file via the Medium API. It is usefull for organizations that need to quickly publish content on Medium." + ] + }, + { + "cell_type": "markdown", + "id": "cc1d8d75-0c1f-41ad-a6b0-b0eb43fcc665", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n- [Programmatically Publish a Markdown File as a Medium Story with Python](https://betterprogramming.pub/programmatically-publish-a-markdown-file-as-a-medium-story-with-python-b2b072a5f968)\n- [Medium API Documentation](https://github.com/Medium/medium-api-docs)" + ] + }, + { + "cell_type": "markdown", + "id": "32f771ab-b85d-44c2-8555-004b07b512ea", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "74c2e136-cd6b-4079-9338-0b609b927692", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e4bad8c4-13c7-4c1c-b97d-46fc1ced422c", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "import requests\nimport json", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "85e28cc8-0742-4aed-a9ee-c0b98cc00de4", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n- `token`: Medium access token. [Instructions to get the token](https://github.com/Medium/medium-api-docs#22-authentication).\n- `file_name`: Name of the Markdown file to be published." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7acc98ec-b364-4164-8524-bb0b7109d6c4", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "token = \"\"\nfile_name = \".md\"", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "252ce263-9e42-4b03-aa2a-57efb0294c64", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "20f812e5-9880-4c5e-92d8-71591450bdc1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Publish article" + ] + }, + { + "cell_type": "markdown", + "id": "f0e2693b-779a-4c19-9c6d-e46c756e8236", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "Long description of the function without break" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "650f0106-6407-4fa8-a4e5-019762a526b1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "# Read the Markdown file\nwith open(file_name, \"r\") as file:\n content = file.read()\n# Set the request parameters\nurl = \"https://api.medium.com/v1/users/me/posts\"\nheaders = {\n \"Authorization\": f\"Bearer {token}\",\n \"Content-Type\": \"application/json\",\n \"Accept\": \"application/json\",\n \"Accept-Charset\": \"utf-8\",\n}\n# Set the payload\npayload = {\n \"title\": \"My Article\",\n \"contentFormat\": \"markdown\",\n \"content\": content,\n \"publishStatus\": \"draft\",\n}\n# Make the request\nresponse = requests.request(\"POST\", url, headers=headers, data=json.dumps(payload))\n# Check the response\nif response.status_code == 200:\n print(\"Article published successfully\")\nelse:\n print(\"Error publishing article\")", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "a4948757-3194-45e2-96f5-2e4463071eb3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "2aff52b9-5335-4240-9306-cb1238b29506", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "743eeca5-8a08-4cde-a397-9eba791aa38b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "print(response.text)", + "outputs": [] + } + ], + "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" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file From afa690d1c9c5a6c2343231007e131a89abd903e5 Mon Sep 17 00:00:00 2001 From: M Sai Kiran Date: Fri, 13 Oct 2023 07:02:38 +0200 Subject: [PATCH 2/8] d1 --- ...um_Publish_article_from_Mardown_file.ipynb | 241 ------------- Medium/sample.ipynb | 341 ++++++++++++++++++ Medium/sample.md | 15 + 3 files changed, 356 insertions(+), 241 deletions(-) delete mode 100644 Medium/Medium_Publish_article_from_Mardown_file.ipynb create mode 100644 Medium/sample.ipynb create mode 100644 Medium/sample.md diff --git a/Medium/Medium_Publish_article_from_Mardown_file.ipynb b/Medium/Medium_Publish_article_from_Mardown_file.ipynb deleted file mode 100644 index 58a2269cf5..0000000000 --- a/Medium/Medium_Publish_article_from_Mardown_file.ipynb +++ /dev/null @@ -1,241 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "b2986071-1a29-4f66-995e-72565d384ce8", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "\"Naas\"" - ] - }, - { - "cell_type": "markdown", - "id": "5d7b0c0b-5e6c-4be3-b901-704fc00b6c08", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "# Medium - Publish article from Mardown file" - ] - }, - { - "cell_type": "markdown", - "id": "ba4944a7-f4e5-4e89-9e3e-b4ee2e12c15f", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**Tags:** #medium #publish #article #markdown #file #api" - ] - }, - { - "cell_type": "markdown", - "id": "c96fc2a3-0910-4b6d-a735-1e83cd5fa24e", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**Author:** [Firstname Lastname]()" - ] - }, - { - "cell_type": "markdown", - "id": "edcf9f6c-c073-46c4-92ab-cc72866daf37", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**Last update:** 2023-10-09 (Created: 2023-10-09)" - ] - }, - { - "cell_type": "markdown", - "id": "9b1586dd-d9e8-4f75-a583-c5cd5952bb05", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**Description:** This notebook explains how to publish an article from a Markdown file via the Medium API. It is usefull for organizations that need to quickly publish content on Medium." - ] - }, - { - "cell_type": "markdown", - "id": "cc1d8d75-0c1f-41ad-a6b0-b0eb43fcc665", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**References:**\n- [Programmatically Publish a Markdown File as a Medium Story with Python](https://betterprogramming.pub/programmatically-publish-a-markdown-file-as-a-medium-story-with-python-b2b072a5f968)\n- [Medium API Documentation](https://github.com/Medium/medium-api-docs)" - ] - }, - { - "cell_type": "markdown", - "id": "32f771ab-b85d-44c2-8555-004b07b512ea", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "## Input" - ] - }, - { - "cell_type": "markdown", - "id": "74c2e136-cd6b-4079-9338-0b609b927692", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Import libraries" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e4bad8c4-13c7-4c1c-b97d-46fc1ced422c", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": "import requests\nimport json", - "outputs": [] - }, - { - "cell_type": "markdown", - "id": "85e28cc8-0742-4aed-a9ee-c0b98cc00de4", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Setup variables\n- `token`: Medium access token. [Instructions to get the token](https://github.com/Medium/medium-api-docs#22-authentication).\n- `file_name`: Name of the Markdown file to be published." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7acc98ec-b364-4164-8524-bb0b7109d6c4", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": "token = \"\"\nfile_name = \".md\"", - "outputs": [] - }, - { - "cell_type": "markdown", - "id": "252ce263-9e42-4b03-aa2a-57efb0294c64", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "## Model" - ] - }, - { - "cell_type": "markdown", - "id": "20f812e5-9880-4c5e-92d8-71591450bdc1", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Publish article" - ] - }, - { - "cell_type": "markdown", - "id": "f0e2693b-779a-4c19-9c6d-e46c756e8236", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "Long description of the function without break" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "650f0106-6407-4fa8-a4e5-019762a526b1", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": "# Read the Markdown file\nwith open(file_name, \"r\") as file:\n content = file.read()\n# Set the request parameters\nurl = \"https://api.medium.com/v1/users/me/posts\"\nheaders = {\n \"Authorization\": f\"Bearer {token}\",\n \"Content-Type\": \"application/json\",\n \"Accept\": \"application/json\",\n \"Accept-Charset\": \"utf-8\",\n}\n# Set the payload\npayload = {\n \"title\": \"My Article\",\n \"contentFormat\": \"markdown\",\n \"content\": content,\n \"publishStatus\": \"draft\",\n}\n# Make the request\nresponse = requests.request(\"POST\", url, headers=headers, data=json.dumps(payload))\n# Check the response\nif response.status_code == 200:\n print(\"Article published successfully\")\nelse:\n print(\"Error publishing article\")", - "outputs": [] - }, - { - "cell_type": "markdown", - "id": "a4948757-3194-45e2-96f5-2e4463071eb3", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "## Output" - ] - }, - { - "cell_type": "markdown", - "id": "2aff52b9-5335-4240-9306-cb1238b29506", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Display result" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "743eeca5-8a08-4cde-a397-9eba791aa38b", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": "print(response.text)", - "outputs": [] - } - ], - "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" - }, - "widgets": { - "application/vnd.jupyter.widget-state+json": { - "state": {}, - "version_major": 2, - "version_minor": 0 - } - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/Medium/sample.ipynb b/Medium/sample.ipynb new file mode 100644 index 0000000000..da742b2d6e --- /dev/null +++ b/Medium/sample.ipynb @@ -0,0 +1,341 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "b2986071-1a29-4f66-995e-72565d384ce8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas\"" + ] + }, + { + "cell_type": "markdown", + "id": "5d7b0c0b-5e6c-4be3-b901-704fc00b6c08", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Medium - Publish article from Mardown file" + ] + }, + { + "cell_type": "markdown", + "id": "ba4944a7-f4e5-4e89-9e3e-b4ee2e12c15f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #medium #publish #article #markdown #file #api" + ] + }, + { + "cell_type": "markdown", + "id": "c96fc2a3-0910-4b6d-a735-1e83cd5fa24e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [SaiKiran M](www.linkedin.com/in/msaikiran9)" + ] + }, + { + "cell_type": "markdown", + "id": "edcf9f6c-c073-46c4-92ab-cc72866daf37", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-10-09 (Created: 2023-10-09)" + ] + }, + { + "cell_type": "markdown", + "id": "9b1586dd-d9e8-4f75-a583-c5cd5952bb05", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook explains how to publish an article from a Markdown file via the Medium API. It is usefull for organizations that need to quickly publish content on Medium." + ] + }, + { + "cell_type": "markdown", + "id": "cc1d8d75-0c1f-41ad-a6b0-b0eb43fcc665", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n", + "- [Programmatically Publish a Markdown File as a Medium Story with Python](https://betterprogramming.pub/programmatically-publish-a-markdown-file-as-a-medium-story-with-python-b2b072a5f968)\n", + "- [Medium API Documentation](https://github.com/Medium/medium-api-docs)" + ] + }, + { + "cell_type": "markdown", + "id": "32f771ab-b85d-44c2-8555-004b07b512ea", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "74c2e136-cd6b-4079-9338-0b609b927692", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "e4bad8c4-13c7-4c1c-b97d-46fc1ced422c", + "metadata": { + "execution": { + "iopub.execute_input": "2023-10-13T04:58:52.827418Z", + "iopub.status.busy": "2023-10-13T04:58:52.827190Z", + "iopub.status.idle": "2023-10-13T04:58:52.831328Z", + "shell.execute_reply": "2023-10-13T04:58:52.830636Z", + "shell.execute_reply.started": "2023-10-13T04:58:52.827395Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "try:\n", + " import naas\n", + " import argparse\n", + " import requests\n", + " import json\n", + "except:\n", + " !pip install requests\n", + " !pip install json" + ] + }, + { + "cell_type": "markdown", + "id": "85e28cc8-0742-4aed-a9ee-c0b98cc00de4", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n", + "- `token`: Medium access token. [Instructions to get the token](https://github.com/Medium/medium-api-docs#22-authentication).\n", + "- `file_name`: Name of the Markdown file to be published." + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "7acc98ec-b364-4164-8524-bb0b7109d6c4", + "metadata": { + "execution": { + "iopub.execute_input": "2023-10-13T04:58:53.851425Z", + "iopub.status.busy": "2023-10-13T04:58:53.851197Z", + "iopub.status.idle": "2023-10-13T04:58:53.999825Z", + "shell.execute_reply": "2023-10-13T04:58:53.999168Z", + "shell.execute_reply.started": "2023-10-13T04:58:53.851402Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "TOKEN = naas.secret.get(name=\"key\")\n", + "file_name = \"sample.md\"" + ] + }, + { + "cell_type": "markdown", + "id": "252ce263-9e42-4b03-aa2a-57efb0294c64", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "20f812e5-9880-4c5e-92d8-71591450bdc1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Publish article" + ] + }, + { + "cell_type": "markdown", + "id": "f0e2693b-779a-4c19-9c6d-e46c756e8236", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "Long description of the function without break" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "650f0106-6407-4fa8-a4e5-019762a526b1", + "metadata": { + "execution": { + "iopub.execute_input": "2023-10-13T04:58:55.646116Z", + "iopub.status.busy": "2023-10-13T04:58:55.645792Z", + "iopub.status.idle": "2023-10-13T04:58:57.239293Z", + "shell.execute_reply": "2023-10-13T04:58:57.238573Z", + "shell.execute_reply.started": "2023-10-13T04:58:55.646081Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Post published successfully!\n", + "Post URL: https://medium.com/@s2612369/sample-post-title-8e6a06a9601c\n" + ] + } + ], + "source": [ + "def publish_post(title, content):\n", + " headers = {\n", + " \"Authorization\": f\"Bearer {TOKEN}\",\n", + " \"Content-Type\": \"application/json\"\n", + " }\n", + " \n", + " payload = {\n", + " \"title\": title,\n", + " \"contentFormat\": \"markdown\",\n", + " \"content\": content,\n", + " \"tags\": [\"example\", \"python\"],\n", + " \"publishStatus\": \"public\",\n", + " \"canonicalUrl\": \"http://example.com/sample\"\n", + " } \n", + " \n", + " response = requests.get(\"https://api.medium.com/v1/me\", headers=headers, params={\"Authorization\": \"Bearer {}\".format(TOKEN)})\n", + " if response.status_code == 200:\n", + " author_id = response.json()['data']['id']\n", + " url = \"https://api.medium.com/v1/users/{}/posts\".format(author_id)\n", + " else:\n", + " return\n", + " \n", + " response = requests.post(url, headers=headers, json=payload)\n", + " if response.status_code == 201:\n", + " return response.json()[\"data\"][\"url\"]\n", + " else:\n", + " raise Exception(f\"Failed to publish post: {response.json()}\")\n", + "\n", + "# Read the content of the Markdown file\n", + "with open(\"sample.md\", \"r\", encoding=\"utf-8\") as markdown_file:\n", + " content = markdown_file.read()\n", + "\n", + "# Publish the post\n", + "post_url = publish_post(\"Sample Post Title\", content)\n", + "\n", + "print(\"Post published successfully!\")\n", + "print(\"Post URL:\", post_url)" + ] + }, + { + "cell_type": "markdown", + "id": "a4948757-3194-45e2-96f5-2e4463071eb3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "2aff52b9-5335-4240-9306-cb1238b29506", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "5b0af2a9-5227-45ac-9da9-d0bffabbbe0c", + "metadata": { + "execution": { + "iopub.execute_input": "2023-10-13T04:58:44.831726Z", + "iopub.status.busy": "2023-10-13T04:58:44.831459Z", + "iopub.status.idle": "2023-10-13T04:58:44.837169Z", + "shell.execute_reply": "2023-10-13T04:58:44.836384Z", + "shell.execute_reply.started": "2023-10-13T04:58:44.831700Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "https://medium.com/@s2612369/sample-post-title-5d8675bc278a\n" + ] + } + ], + "source": [ + "print(post_url)" + ] + } + ], + "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" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Medium/sample.md b/Medium/sample.md new file mode 100644 index 0000000000..413637463a --- /dev/null +++ b/Medium/sample.md @@ -0,0 +1,15 @@ +# Naas Templates[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) +(aka the "awesome-notebooks") + +## What is the objective of this repository ? +The objective of this repository is to create the largest catalog of production-ready Jupyter Notebooks templates. With those templates, it becomes easy to create data products (analytical dashboards, automation/AI engines and more). + +Each of these templates adheres to a consistent framework, designed to expedite your coding process. While these templates are designed for ease of use, some may require data science skills for setup, particularly those that interface with third-party tools via API. These templates can function independently, but they also serve as integral components of data products. Consider them as the essential parts needed to assemble your 'car engine'. By developing these templates and ensuring their standalone functionality, we streamline the process of data product development, as we already comprehend the operation of some parts within it. + +All templates are readily accessible on [GitHub](https://github.com/jupyter-naas/awesome-notebooks) or via [Naas Search](https://naas.ai/search). + +![](https://site.naas.ai/assets/images/NaasSearch-1a3b28f814a61bfcbb1511997970a62d.gif) + +## How is organized a template? + +To ensure the quality of the templates, we have defined a framework. Each notebook shall be organized as follow. \ No newline at end of file From 4d5e8b5aaafc9d29eb92d6a2f917ad2277fd56a0 Mon Sep 17 00:00:00 2001 From: M Sai Kiran Date: Fri, 13 Oct 2023 13:26:41 +0200 Subject: [PATCH 3/8] 1 --- Medium/sample.ipynb | 60 ++++++--------------------------------------- 1 file changed, 8 insertions(+), 52 deletions(-) diff --git a/Medium/sample.ipynb b/Medium/sample.ipynb index da742b2d6e..e6fe4cc5b3 100644 --- a/Medium/sample.ipynb +++ b/Medium/sample.ipynb @@ -103,16 +103,9 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": null, "id": "e4bad8c4-13c7-4c1c-b97d-46fc1ced422c", "metadata": { - "execution": { - "iopub.execute_input": "2023-10-13T04:58:52.827418Z", - "iopub.status.busy": "2023-10-13T04:58:52.827190Z", - "iopub.status.idle": "2023-10-13T04:58:52.831328Z", - "shell.execute_reply": "2023-10-13T04:58:52.830636Z", - "shell.execute_reply.started": "2023-10-13T04:58:52.827395Z" - }, "papermill": {}, "tags": [] }, @@ -143,16 +136,9 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "id": "7acc98ec-b364-4164-8524-bb0b7109d6c4", "metadata": { - "execution": { - "iopub.execute_input": "2023-10-13T04:58:53.851425Z", - "iopub.status.busy": "2023-10-13T04:58:53.851197Z", - "iopub.status.idle": "2023-10-13T04:58:53.999825Z", - "shell.execute_reply": "2023-10-13T04:58:53.999168Z", - "shell.execute_reply.started": "2023-10-13T04:58:53.851402Z" - }, "papermill": {}, "tags": [] }, @@ -197,29 +183,13 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": null, "id": "650f0106-6407-4fa8-a4e5-019762a526b1", "metadata": { - "execution": { - "iopub.execute_input": "2023-10-13T04:58:55.646116Z", - "iopub.status.busy": "2023-10-13T04:58:55.645792Z", - "iopub.status.idle": "2023-10-13T04:58:57.239293Z", - "shell.execute_reply": "2023-10-13T04:58:57.238573Z", - "shell.execute_reply.started": "2023-10-13T04:58:55.646081Z" - }, "papermill": {}, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Post published successfully!\n", - "Post URL: https://medium.com/@s2612369/sample-post-title-8e6a06a9601c\n" - ] - } - ], + "outputs": [], "source": [ "def publish_post(title, content):\n", " headers = {\n", @@ -284,29 +254,15 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "id": "5b0af2a9-5227-45ac-9da9-d0bffabbbe0c", "metadata": { - "execution": { - "iopub.execute_input": "2023-10-13T04:58:44.831726Z", - "iopub.status.busy": "2023-10-13T04:58:44.831459Z", - "iopub.status.idle": "2023-10-13T04:58:44.837169Z", - "shell.execute_reply": "2023-10-13T04:58:44.836384Z", - "shell.execute_reply.started": "2023-10-13T04:58:44.831700Z" - }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "https://medium.com/@s2612369/sample-post-title-5d8675bc278a\n" - ] - } - ], + "outputs": [], "source": [ - "print(post_url)" + "print(post_url)\n", + "naas.secret.delete(name=\"key\")" ] } ], From 5538c654fcab1c36ff9bf6fcdf6561d8786d4187 Mon Sep 17 00:00:00 2001 From: M Sai Kiran Date: Fri, 13 Oct 2023 13:29:38 +0200 Subject: [PATCH 4/8] 2 --- Medium/sample.ipynb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Medium/sample.ipynb b/Medium/sample.ipynb index e6fe4cc5b3..b7b3d76567 100644 --- a/Medium/sample.ipynb +++ b/Medium/sample.ipynb @@ -113,12 +113,12 @@ "source": [ "try:\n", " import naas\n", - " import argparse\n", - " import requests\n", " import json\n", - "except:\n", + " import requests\n", + "except ImportError:\n", + " print(\"One or more modules not found. Installing necessary packages...\")\n", " !pip install requests\n", - " !pip install json" + " import requests" ] }, { @@ -261,8 +261,7 @@ }, "outputs": [], "source": [ - "print(post_url)\n", - "naas.secret.delete(name=\"key\")" + "print(post_url)" ] } ], From cf4050eee18dfd0c40a5ee7d81287ca98f84d011 Mon Sep 17 00:00:00 2001 From: Sriniketh J <81156510+srini047@users.noreply.github.com> Date: Fri, 13 Oct 2023 23:54:29 +0530 Subject: [PATCH 5/8] Delete Medium/sample.md --- Medium/sample.md | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 Medium/sample.md diff --git a/Medium/sample.md b/Medium/sample.md deleted file mode 100644 index 413637463a..0000000000 --- a/Medium/sample.md +++ /dev/null @@ -1,15 +0,0 @@ -# Naas Templates[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) -(aka the "awesome-notebooks") - -## What is the objective of this repository ? -The objective of this repository is to create the largest catalog of production-ready Jupyter Notebooks templates. With those templates, it becomes easy to create data products (analytical dashboards, automation/AI engines and more). - -Each of these templates adheres to a consistent framework, designed to expedite your coding process. While these templates are designed for ease of use, some may require data science skills for setup, particularly those that interface with third-party tools via API. These templates can function independently, but they also serve as integral components of data products. Consider them as the essential parts needed to assemble your 'car engine'. By developing these templates and ensuring their standalone functionality, we streamline the process of data product development, as we already comprehend the operation of some parts within it. - -All templates are readily accessible on [GitHub](https://github.com/jupyter-naas/awesome-notebooks) or via [Naas Search](https://naas.ai/search). - -![](https://site.naas.ai/assets/images/NaasSearch-1a3b28f814a61bfcbb1511997970a62d.gif) - -## How is organized a template? - -To ensure the quality of the templates, we have defined a framework. Each notebook shall be organized as follow. \ No newline at end of file From 616699e2b71a42e1023b7d093bebcad1296a7cf3 Mon Sep 17 00:00:00 2001 From: M Sai Kiran Date: Sat, 14 Oct 2023 08:04:53 +0200 Subject: [PATCH 6/8] rev --- ...um_Publish_article_from_Mardown_file.ipynb} | 18 +++++++++++------- Medium/sample.md | 15 --------------- 2 files changed, 11 insertions(+), 22 deletions(-) rename Medium/{sample.ipynb => Medium_Publish_article_from_Mardown_file.ipynb} (89%) delete mode 100644 Medium/sample.md diff --git a/Medium/sample.ipynb b/Medium/Medium_Publish_article_from_Mardown_file.ipynb similarity index 89% rename from Medium/sample.ipynb rename to Medium/Medium_Publish_article_from_Mardown_file.ipynb index b7b3d76567..b47c4bb5e6 100644 --- a/Medium/sample.ipynb +++ b/Medium/Medium_Publish_article_from_Mardown_file.ipynb @@ -118,7 +118,8 @@ "except ImportError:\n", " print(\"One or more modules not found. Installing necessary packages...\")\n", " !pip install requests\n", - " import requests" + " import requests\n", + "#step 1 : import the necessary libraries here i.e., requests as json and naas are already present." ] }, { @@ -144,8 +145,9 @@ }, "outputs": [], "source": [ + "#step 2 : store the API token that's generated from Medium -> settings -> security and apps -> integration tokens into naas.\n", "TOKEN = naas.secret.get(name=\"key\")\n", - "file_name = \"sample.md\"" + "file_name = \"sample.md\" #this is file to be uploaded in medium as an article ." ] }, { @@ -191,6 +193,8 @@ }, "outputs": [], "source": [ + "#step 3 : In this step we setup publish_post fill the necessary headers & url to send the auth request.It'll send back a \n", + "#author_id user's unique identifier.And we will request to post content to the url containing the author_id at -> #1\n", "def publish_post(title, content):\n", " headers = {\n", " \"Authorization\": f\"Bearer {TOKEN}\",\n", @@ -205,25 +209,25 @@ " \"publishStatus\": \"public\",\n", " \"canonicalUrl\": \"http://example.com/sample\"\n", " } \n", - " \n", + " #get the author's complete api end point url.\n", " response = requests.get(\"https://api.medium.com/v1/me\", headers=headers, params={\"Authorization\": \"Bearer {}\".format(TOKEN)})\n", " if response.status_code == 200:\n", " author_id = response.json()['data']['id']\n", " url = \"https://api.medium.com/v1/users/{}/posts\".format(author_id)\n", " else:\n", " return\n", - " \n", - " response = requests.post(url, headers=headers, json=payload)\n", + " #post the data .\n", + " response = requests.post(url, headers=headers, json=payload) #1\n", " if response.status_code == 201:\n", " return response.json()[\"data\"][\"url\"]\n", " else:\n", " raise Exception(f\"Failed to publish post: {response.json()}\")\n", "\n", - "# Read the content of the Markdown file\n", + "#step 4 : Read the content of the Markdown file here let's say from \"sample.md\" file\n", "with open(\"sample.md\", \"r\", encoding=\"utf-8\") as markdown_file:\n", " content = markdown_file.read()\n", "\n", - "# Publish the post\n", + "#step 5 : Publish the post\n", "post_url = publish_post(\"Sample Post Title\", content)\n", "\n", "print(\"Post published successfully!\")\n", diff --git a/Medium/sample.md b/Medium/sample.md deleted file mode 100644 index 413637463a..0000000000 --- a/Medium/sample.md +++ /dev/null @@ -1,15 +0,0 @@ -# Naas Templates[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) -(aka the "awesome-notebooks") - -## What is the objective of this repository ? -The objective of this repository is to create the largest catalog of production-ready Jupyter Notebooks templates. With those templates, it becomes easy to create data products (analytical dashboards, automation/AI engines and more). - -Each of these templates adheres to a consistent framework, designed to expedite your coding process. While these templates are designed for ease of use, some may require data science skills for setup, particularly those that interface with third-party tools via API. These templates can function independently, but they also serve as integral components of data products. Consider them as the essential parts needed to assemble your 'car engine'. By developing these templates and ensuring their standalone functionality, we streamline the process of data product development, as we already comprehend the operation of some parts within it. - -All templates are readily accessible on [GitHub](https://github.com/jupyter-naas/awesome-notebooks) or via [Naas Search](https://naas.ai/search). - -![](https://site.naas.ai/assets/images/NaasSearch-1a3b28f814a61bfcbb1511997970a62d.gif) - -## How is organized a template? - -To ensure the quality of the templates, we have defined a framework. Each notebook shall be organized as follow. \ No newline at end of file From eb173b88a1806217b74869101f6038621a5cc0fa Mon Sep 17 00:00:00 2001 From: M Sai Kiran Date: Sat, 14 Oct 2023 08:05:38 +0200 Subject: [PATCH 7/8] 1 --- Medium/Medium_Publish_article_from_Mardown_file.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Medium/Medium_Publish_article_from_Mardown_file.ipynb b/Medium/Medium_Publish_article_from_Mardown_file.ipynb index b47c4bb5e6..79923f62ad 100644 --- a/Medium/Medium_Publish_article_from_Mardown_file.ipynb +++ b/Medium/Medium_Publish_article_from_Mardown_file.ipynb @@ -231,7 +231,7 @@ "post_url = publish_post(\"Sample Post Title\", content)\n", "\n", "print(\"Post published successfully!\")\n", - "print(\"Post URL:\", post_url)" + "print(\"Post URL:\", post_url) " ] }, { @@ -265,7 +265,7 @@ }, "outputs": [], "source": [ - "print(post_url)" + "print(post_url) #this will give the url where your post is live" ] } ], From 62958b1fd5963e2c0c72ba71ad390d1504e565be Mon Sep 17 00:00:00 2001 From: Sriniketh J <81156510+srini047@users.noreply.github.com> Date: Mon, 16 Oct 2023 21:57:10 +0530 Subject: [PATCH 8/8] fix: minor bugs --- Medium/Medium_Publish_article_from_Mardown_file.ipynb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Medium/Medium_Publish_article_from_Mardown_file.ipynb b/Medium/Medium_Publish_article_from_Mardown_file.ipynb index 79923f62ad..49a647f3fe 100644 --- a/Medium/Medium_Publish_article_from_Mardown_file.ipynb +++ b/Medium/Medium_Publish_article_from_Mardown_file.ipynb @@ -146,7 +146,7 @@ "outputs": [], "source": [ "#step 2 : store the API token that's generated from Medium -> settings -> security and apps -> integration tokens into naas.\n", - "TOKEN = naas.secret.get(name=\"key\")\n", + "TOKEN = naas.secret.get(name=\"MEDIUM_TOKEN\")\n", "file_name = \"sample.md\" #this is file to be uploaded in medium as an article ." ] }, @@ -230,8 +230,7 @@ "#step 5 : Publish the post\n", "post_url = publish_post(\"Sample Post Title\", content)\n", "\n", - "print(\"Post published successfully!\")\n", - "print(\"Post URL:\", post_url) " + "print(\"Post published successfully!\")" ] }, { @@ -265,7 +264,7 @@ }, "outputs": [], "source": [ - "print(post_url) #this will give the url where your post is live" + "print(post_url)" ] } ],