Skip to content

Commit

Permalink
Merge pull request #2477 from jupyter-naas/2476-naas-credits-export-c…
Browse files Browse the repository at this point in the history
…urrent-transaction

feat(Naas Credits): Add Export current transaction
  • Loading branch information
FlorentLvr authored Dec 21, 2023
2 parents e9d8906 + 9121176 commit 335108a
Show file tree
Hide file tree
Showing 3 changed files with 298 additions and 38 deletions.
282 changes: 282 additions & 0 deletions Naas Credits/Naas_Credits_Export_current_transactions_to_Excel.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "168abe1a-0f00-446c-bd08-74b5cb43c4a4",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"<img width=\"8%\" alt=\"Naas.png\" src=\"https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/.github/assets/logos/Naas.png\" style=\"border-radius: 15%\">"
]
},
{
"cell_type": "markdown",
"id": "d42f1fdd-8fd8-4213-8e15-78f6281e6344",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"# Naas Credits - Export current transactions to Excel"
]
},
{
"cell_type": "markdown",
"id": "09160566-d6dd-4912-8aa4-df8f40036d72",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Tags:** #naascredits #export #transaction #current #excel #naas"
]
},
{
"cell_type": "markdown",
"id": "026cfb17-7b38-4ebb-ae40-8147b11a6ab6",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)"
]
},
{
"cell_type": "markdown",
"id": "cfe15482-7cfe-4de2-a83f-e91aeffa3e3c",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Last update:** 2023-12-21 (Created: 2023-12-21)"
]
},
{
"cell_type": "markdown",
"id": "fce74c2a-914f-47d8-acef-dadce3d4da59",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Description:** This notebook will export your current transactions (transactions done this month) from Naas Credits API and save it to an Excel file."
]
},
{
"cell_type": "markdown",
"id": "2c60ac49-a891-462d-86ae-5890bb801ab8",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**References:**\n",
"- [Naas Credits driver](https://github.com/jupyter-naas/drivers/blob/main/naas_drivers/tools/naas_credits.py)"
]
},
{
"cell_type": "markdown",
"id": "1de76aea-f175-4f80-b0de-f827518a47b6",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Input"
]
},
{
"cell_type": "markdown",
"id": "0eab4379-7117-468a-86e9-5ec4701d1a00",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7f994733-0621-4cce-8fda-f1a3cc2ee3d2",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"from naas_drivers import naascredits\n",
"from datetime import datetime\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"id": "35b0528a-1021-4cfc-8363-03ecbb0dd08a",
"metadata": {},
"source": [
"### Setup variables\n",
"- `file_path`: Excel file path to be saved in your local env."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d0ac086d-1dba-4bbf-a692-f7bf0832f24e",
"metadata": {},
"outputs": [],
"source": [
"file_path = f\"{datetime.now().isoformat()}_currents_transactions.xlsx\""
]
},
{
"cell_type": "markdown",
"id": "3af3ebc4-3b52-4cc4-8974-3d222a1cb0b1",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Model"
]
},
{
"cell_type": "markdown",
"id": "9445fab9-f0ac-4af5-b3d3-d4990137f9d4",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Get current transaction"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "06a55817-cb91-4f9f-ae7e-25595be18237",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"data = naascredits.connect().transactions.get_currents()"
]
},
{
"cell_type": "markdown",
"id": "30a1a7a6-5121-4c76-859e-00e0ea6cb364",
"metadata": {
"execution": {
"iopub.execute_input": "2023-12-21T08:53:33.705308Z",
"iopub.status.busy": "2023-12-21T08:53:33.705055Z",
"iopub.status.idle": "2023-12-21T08:53:33.708305Z",
"shell.execute_reply": "2023-12-21T08:53:33.707644Z",
"shell.execute_reply.started": "2023-12-21T08:53:33.705284Z"
},
"tags": []
},
"source": [
"### Convert data to DataFrame"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eb2a040e-dd00-4afa-933b-9ea2497d83dc",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"df = pd.DataFrame(data)\n",
"print(\"Current balance:\", df.CREDIT.sum())"
]
},
{
"cell_type": "markdown",
"id": "775fe31b-d335-4b03-92e5-ed11f25f953e",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Output"
]
},
{
"cell_type": "markdown",
"id": "9e8ea457-99a5-40ff-ac9b-28f195511068",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Save data to Excel file"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bc039287-6129-4f0b-8966-80bb8985b989",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"df.to_excel(\n",
" file_path,\n",
" sheet_name=\"Export\",\n",
" index=False,\n",
")\n",
"print(f\"Excel file successfully saved: {file_path}\")"
]
},
{
"cell_type": "markdown",
"id": "e71dce99-777c-476f-98c6-81ac62025df2",
"metadata": {
"papermill": {},
"tags": []
},
"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"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"tags": []
},
"source": [
"# Naas - Credits Get Balance\n",
"# Naas Credits - Get Balance\n",
"<a href=\"https://app.naas.ai/user-redirect/naas/downloader?url=https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/Naas/Naas_Credits_Get_Balance.ipynb\" target=\"_parent\"><img src=\"https://naasai-public.s3.eu-west-3.amazonaws.com/Open_in_Naas_Lab.svg\"/></a><br><br><a href=\"https://bit.ly/3JyWIk6\">Give Feedback</a> | <a href=\"https://github.com/jupyter-naas/awesome-notebooks/issues/new?assignees=&labels=bug&template=bug_report.md&title=Naas+-+Credits+Get+Balance:+Error+short+description\">Bug report</a>"
]
},
Expand Down Expand Up @@ -60,7 +60,7 @@
"tags": []
},
"source": [
"**Last update:** 2023-04-12 (Created: 2021-11-17)"
"**Last update:** 2023-12-21 (Created: 2021-11-17)"
]
},
{
Expand Down Expand Up @@ -130,7 +130,7 @@
"tags": []
},
"source": [
"### Function"
"### Get balance"
]
},
{
Expand All @@ -143,7 +143,8 @@
},
"outputs": [],
"source": [
"balance = naascredits.connect().get_balance()"
"balance = naascredits.connect().get_balance()\n",
"print(balance)"
]
},
{
Expand Down Expand Up @@ -205,7 +206,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.9.6"
},
"naas": {
"notebook_id": "b8e8498be8e2a6e4ed47256dd6b987fc934f372db1ce9b0ba198bd19514296ca",
Expand All @@ -227,4 +228,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
Loading

0 comments on commit 335108a

Please sign in to comment.