Skip to content

Commit

Permalink
Merge pull request #2570 from jupyter-naas/2569-pennylane-invoices-in…
Browse files Browse the repository at this point in the history
…tegration

feat: add Pennylane integration
  • Loading branch information
FlorentLvr authored Oct 4, 2024
2 parents 15f27cf + 530dbbb commit 01aa307
Show file tree
Hide file tree
Showing 5 changed files with 707 additions and 0 deletions.
Binary file added .github/assets/logos/Pennylane.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
239 changes: 239 additions & 0 deletions Pennylane/Pennylane_List_all_categories.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "1ec65662-8eb6-4a98-a16e-ffc3729252b6",
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-23T14:22:16.610471Z",
"iopub.status.busy": "2021-02-23T14:22:16.610129Z",
"iopub.status.idle": "2021-02-23T14:22:16.627784Z",
"shell.execute_reply": "2021-02-23T14:22:16.626866Z",
"shell.execute_reply.started": "2021-02-23T14:22:16.610384Z"
},
"papermill": {},
"tags": []
},
"source": [
"<img width=\"8%\" alt=\"Pennylane.png\" src=\"https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/.github/assets/logos/Pennylane.png\" style=\"border-radius: 15%\">"
]
},
{
"cell_type": "markdown",
"id": "hairy-interstate",
"metadata": {},
"source": [
"# Pennylane - List all categories"
]
},
{
"cell_type": "markdown",
"id": "db03090b-015f-4b1b-8c7c-ba11f37d60b5",
"metadata": {},
"source": [
"**Tags:** #pennylane #list #categories #snippet"
]
},
{
"cell_type": "markdown",
"id": "c54c97eb-8d4d-417c-a402-7adf5327d7fb",
"metadata": {},
"source": [
"**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)"
]
},
{
"cell_type": "markdown",
"id": "ed962863-54e5-48e4-aa48-877adeba86fc",
"metadata": {},
"source": [
"**Description:** This endpoint returns a list of categories."
]
},
{
"cell_type": "markdown",
"id": "fdcf05b5-17d7-4c11-88ec-f722cf264a7f",
"metadata": {},
"source": [
"## Input"
]
},
{
"cell_type": "markdown",
"id": "75da13af-72c2-44b9-8c06-ed3bfa4700ac",
"metadata": {
"execution": {
"iopub.execute_input": "2022-08-31T10:54:23.866665Z",
"iopub.status.busy": "2022-08-31T10:54:23.866431Z",
"iopub.status.idle": "2022-08-31T10:54:23.871270Z",
"shell.execute_reply": "2022-08-31T10:54:23.870705Z",
"shell.execute_reply.started": "2022-08-31T10:54:23.866641Z"
},
"tags": []
},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b5605c12-6814-4d98-99b0-aaaa4526014f",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import requests\n",
"import pandas as pd\n",
"import naas_python #to use this lib create your account on naas.ai"
]
},
{
"cell_type": "markdown",
"id": "1b6ad1a8-308e-4778-963c-fc21d492a1a9",
"metadata": {},
"source": [
"### Setup variables"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "06d385f7-6b96-4e95-8721-b02ef7c52c83",
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"api_token = naas_python.secret.get(\"PENNYLANE_API_TOKEN\").value or \"YOUR_PENNYLANE_API_TOKEN\" # if you don't have a naas.ai account, add api_token as string"
]
},
{
"cell_type": "markdown",
"id": "e2b06c06-c20d-4d1a-a228-dca532603925",
"metadata": {},
"source": [
"## Model"
]
},
{
"cell_type": "markdown",
"id": "14cd5a2a-8e0a-45f6-a31c-f487950db30d",
"metadata": {},
"source": [
"### List all categories"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4a62312c-53f7-4285-b1fd-5dde2592022c",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"def list_all_catgories(\n",
" api_token,\n",
" per_page=50,\n",
" sort=None,\n",
" filter=None,\n",
"):\n",
" url = \"https://app.pennylane.com/api/external/v1/categories\"\n",
" headers = {\n",
" \"Accept\": \"application/json\",\n",
" \"Authorization\": f\"Bearer {api_token}\"\n",
" }\n",
" data = []\n",
" page = 1\n",
" while True:\n",
" # Get data\n",
" res_json = []\n",
" params = {\n",
" \"page\": page,\n",
" \"per_page\": per_page,\n",
" }\n",
" res = requests.get(url, headers=headers, params=params)\n",
" res.raise_for_status()\n",
" if res.status_code == 200:\n",
" result = res.json().get(\"categories\")\n",
"\n",
" # Concat result\n",
" if len(result) > 0:\n",
" data += result\n",
" page += 1\n",
" else:\n",
" break\n",
" return data\n",
"\n",
"result = list_all_catgories(api_token)"
]
},
{
"cell_type": "markdown",
"id": "21da518a-e9a5-4655-87a2-52e005f31dbe",
"metadata": {},
"source": [
"## Output"
]
},
{
"cell_type": "markdown",
"id": "08861687-49bb-4c65-83a3-a483a8c4b708",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Display result"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b123c08c-124a-44ac-bc44-fc72a7768434",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"df = pd.DataFrame(result)\n",
"print(\"Rows:\", len(df))\n",
"df.head(5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "078e5821-d264-48b4-a1d1-7bfbc1c05490",
"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"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 01aa307

Please sign in to comment.