-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2477 from jupyter-naas/2476-naas-credits-export-c…
…urrent-transaction feat(Naas Credits): Add Export current transaction
- Loading branch information
Showing
3 changed files
with
298 additions
and
38 deletions.
There are no files selected for viewing
282 changes: 282 additions & 0 deletions
282
Naas Credits/Naas_Credits_Export_current_transactions_to_Excel.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.