Notebooks >> Scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

434 lines
13 KiB

{
"cells": [
{
"cell_type": "markdown",
"id": "private-antigua",
"metadata": {
"execution": {
"iopub.execute_input": "2021-01-26T14:19:41.734342Z",
"iopub.status.busy": "2021-01-26T14:19:41.734061Z",
"iopub.status.idle": "2021-01-26T14:19:41.746082Z",
"shell.execute_reply": "2021-01-26T14:19:41.745168Z",
"shell.execute_reply.started": "2021-01-26T14:19:41.734276Z"
},
"papermill": {},
"tags": []
},
"source": [
"<img width=\"10%\" alt=\"Naas\" src=\"https://landen.imgix.net/jtci2pxwjczr/assets/5ice39g4.png?w=160\"/>"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ff43d718-37c8-4b8e-98ae-8bc851fb23ba",
"metadata": {
"execution": {
"iopub.execute_input": "2021-10-15T01:26:21.735530Z",
"iopub.status.busy": "2021-10-15T01:26:21.734797Z",
"iopub.status.idle": "2021-10-15T01:26:21.756872Z",
"shell.execute_reply": "2021-10-15T01:26:21.753917Z",
"shell.execute_reply.started": "2021-10-15T01:26:21.735431Z"
}
},
"outputs": [
{
"data": {
"application/json": {
"cell": {
"!": "OSMagics",
"HTML": "Other",
"SVG": "Other",
"bash": "Other",
"capture": "ExecutionMagics",
"debug": "ExecutionMagics",
"file": "Other",
"html": "DisplayMagics",
"javascript": "DisplayMagics",
"js": "DisplayMagics",
"latex": "DisplayMagics",
"markdown": "DisplayMagics",
"perl": "Other",
"prun": "ExecutionMagics",
"pypy": "Other",
"python": "Other",
"python2": "Other",
"python3": "Other",
"ruby": "Other",
"script": "ScriptMagics",
"sh": "Other",
"svg": "DisplayMagics",
"sx": "OSMagics",
"system": "OSMagics",
"time": "ExecutionMagics",
"timeit": "ExecutionMagics",
"writefile": "OSMagics"
},
"line": {
"alias": "OSMagics",
"alias_magic": "BasicMagics",
"autoawait": "AsyncMagics",
"autocall": "AutoMagics",
"automagic": "AutoMagics",
"autosave": "KernelMagics",
"bookmark": "OSMagics",
"cat": "Other",
"cd": "OSMagics",
"clear": "KernelMagics",
"colors": "BasicMagics",
"conda": "PackagingMagics",
"config": "ConfigMagics",
"connect_info": "KernelMagics",
"cp": "Other",
"debug": "ExecutionMagics",
"dhist": "OSMagics",
"dirs": "OSMagics",
"doctest_mode": "BasicMagics",
"ed": "Other",
"edit": "KernelMagics",
"env": "OSMagics",
"gui": "BasicMagics",
"hist": "Other",
"history": "HistoryMagics",
"killbgscripts": "ScriptMagics",
"ldir": "Other",
"less": "KernelMagics",
"lf": "Other",
"lk": "Other",
"ll": "Other",
"load": "CodeMagics",
"load_ext": "ExtensionMagics",
"loadpy": "CodeMagics",
"logoff": "LoggingMagics",
"logon": "LoggingMagics",
"logstart": "LoggingMagics",
"logstate": "LoggingMagics",
"logstop": "LoggingMagics",
"ls": "Other",
"lsmagic": "BasicMagics",
"lx": "Other",
"macro": "ExecutionMagics",
"magic": "BasicMagics",
"man": "KernelMagics",
"matplotlib": "PylabMagics",
"mkdir": "Other",
"more": "KernelMagics",
"mv": "Other",
"notebook": "BasicMagics",
"page": "BasicMagics",
"pastebin": "CodeMagics",
"pdb": "ExecutionMagics",
"pdef": "NamespaceMagics",
"pdoc": "NamespaceMagics",
"pfile": "NamespaceMagics",
"pinfo": "NamespaceMagics",
"pinfo2": "NamespaceMagics",
"pip": "PackagingMagics",
"popd": "OSMagics",
"pprint": "BasicMagics",
"precision": "BasicMagics",
"prun": "ExecutionMagics",
"psearch": "NamespaceMagics",
"psource": "NamespaceMagics",
"pushd": "OSMagics",
"pwd": "OSMagics",
"pycat": "OSMagics",
"pylab": "PylabMagics",
"qtconsole": "KernelMagics",
"quickref": "BasicMagics",
"recall": "HistoryMagics",
"rehashx": "OSMagics",
"reload_ext": "ExtensionMagics",
"rep": "Other",
"rerun": "HistoryMagics",
"reset": "NamespaceMagics",
"reset_selective": "NamespaceMagics",
"rm": "Other",
"rmdir": "Other",
"run": "ExecutionMagics",
"save": "CodeMagics",
"sc": "OSMagics",
"set_env": "OSMagics",
"store": "StoreMagics",
"sx": "OSMagics",
"system": "OSMagics",
"tb": "ExecutionMagics",
"time": "ExecutionMagics",
"timeit": "ExecutionMagics",
"unalias": "OSMagics",
"unload_ext": "ExtensionMagics",
"who": "NamespaceMagics",
"who_ls": "NamespaceMagics",
"whos": "NamespaceMagics",
"xdel": "NamespaceMagics",
"xmode": "BasicMagics"
}
},
"text/plain": [
"Available line magics:\n",
"%alias %alias_magic %autoawait %autocall %automagic %autosave %bookmark %cat %cd %clear %colors %conda %config %connect_info %cp %debug %dhist %dirs %doctest_mode %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %lf %lk %ll %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %lx %macro %magic %man %matplotlib %mkdir %more %mv %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %pip %popd %pprint %precision %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %rep %rerun %reset %reset_selective %rm %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode\n",
"\n",
"Available cell magics:\n",
"%%! %%HTML %%SVG %%bash %%capture %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile\n",
"\n",
"Automagic is ON, % prefix IS NOT needed for line magics."
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# This will list all magic commands\n",
"%lsmagic"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bc0a93c6-8119-40ef-af16-c64ca8186b1f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "temporal-charleston",
"metadata": {
"execution": {
"iopub.execute_input": "2021-01-26T14:20:23.712683Z",
"iopub.status.busy": "2021-01-26T14:20:23.712460Z",
"iopub.status.idle": "2021-01-26T14:20:23.715365Z",
"shell.execute_reply": "2021-01-26T14:20:23.714680Z",
"shell.execute_reply.started": "2021-01-26T14:20:23.712660Z"
},
"papermill": {},
"tags": []
},
"source": [
"# Github - Download file from url\n",
"<a href=\"https://app.naas.ai/user-redirect/naas/downloader?url=https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/Github/Github_Download_file_from_url.ipynb\" target=\"_parent\"><img src=\"https://img.shields.io/badge/-Open%20in%20Naas-success?labelColor=000000&logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iMTAyNHB4IiBoZWlnaHQ9IjEwMjRweCIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIj4KIDwhLS0gR2VuZXJhdGVkIGJ5IFBpeGVsbWF0b3IgUHJvIDIuMC41IC0tPgogPGRlZnM+CiAgPHRleHQgaWQ9InN0cmluZyIgdHJhbnNmb3JtPSJtYXRyaXgoMS4wIDAuMCAwLjAgMS4wIDIyOC4wIDU0LjUpIiBmb250LWZhbWlseT0iQ29tZm9ydGFhLVJlZ3VsYXIsIENvbWZvcnRhYSIgZm9udC1zaXplPSI4MDAiIHRleHQtZGVjb3JhdGlvbj0ibm9uZSIgZmlsbD0iI2ZmZmZmZiIgeD0iMS4xOTk5OTk5OTk5OTk5ODg2IiB5PSI3MDUuMCI+bjwvdGV4dD4KIDwvZGVmcz4KIDx1c2UgaWQ9Im4iIHhsaW5rOmhyZWY9IiNzdHJpbmciLz4KPC9zdmc+Cg==\"/></a>"
]
},
{
"cell_type": "markdown",
"id": "tags_cell",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Tags:** #github #productivity #code"
]
},
{
"cell_type": "markdown",
"id": "input_cell",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Input"
]
},
{
"cell_type": "markdown",
"id": "interpreted-picnic",
"metadata": {
"execution": {
"iopub.execute_input": "2021-01-26T14:20:42.280435Z",
"iopub.status.busy": "2021-01-26T14:20:42.280200Z",
"iopub.status.idle": "2021-01-26T14:20:42.283029Z",
"shell.execute_reply": "2021-01-26T14:20:42.282302Z",
"shell.execute_reply.started": "2021-01-26T14:20:42.280412Z"
},
"papermill": {},
"tags": []
},
"source": [
"### Import needed library"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "handmade-winter",
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-28T10:55:28.843048Z",
"iopub.status.busy": "2021-02-28T10:55:28.842782Z",
"iopub.status.idle": "2021-02-28T10:55:31.722822Z",
"shell.execute_reply": "2021-02-28T10:55:31.722138Z",
"shell.execute_reply.started": "2021-02-28T10:55:28.842987Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"import uuid\n",
"\n",
"import naas\n",
"import requests"
]
},
{
"cell_type": "markdown",
"id": "model_cell",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Model"
]
},
{
"cell_type": "markdown",
"id": "inner-redhead",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Default Github file for testing purpose"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "nutritional-egyptian",
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-28T10:55:32.727530Z",
"iopub.status.busy": "2021-02-28T10:55:32.727286Z",
"iopub.status.idle": "2021-02-28T10:55:32.730550Z",
"shell.execute_reply": "2021-02-28T10:55:32.729877Z",
"shell.execute_reply.started": "2021-02-28T10:55:32.727505Z"
},
"papermill": {},
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"target = \"https://github.com/jupyter-naas/awesome-notebooks/blob/master/Plotly/Create%20Candlestick%20chart.ipynb\""
]
},
{
"cell_type": "markdown",
"id": "polished-creek",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Convert url to downloadable one"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "written-bicycle",
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-28T10:55:33.921701Z",
"iopub.status.busy": "2021-02-28T10:55:33.921447Z",
"iopub.status.idle": "2021-02-28T10:55:33.925422Z",
"shell.execute_reply": "2021-02-28T10:55:33.924798Z",
"shell.execute_reply.started": "2021-02-28T10:55:33.921678Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"# https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/Dataviz/Plotly/Create%20Candlestick%20chart.ipynb\n",
"raw_target = target.replace(\"https://github.com/\", \"https://raw.githubusercontent.com/\")\n",
"raw_target = raw_target.replace(\"/blob/\", \"/\")\n",
"print(raw_target)"
]
},
{
"cell_type": "markdown",
"id": "output_cell",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Output"
]
},
{
"cell_type": "markdown",
"id": "earned-slovakia",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Dowload file locally"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "centered-morris",
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-28T10:55:38.998295Z",
"iopub.status.busy": "2021-02-28T10:55:38.998044Z",
"iopub.status.idle": "2021-02-28T10:55:39.122045Z",
"shell.execute_reply": "2021-02-28T10:55:39.121369Z",
"shell.execute_reply.started": "2021-02-28T10:55:38.998273Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"import urllib.parse\n",
"\n",
"r = requests.get(raw_target)\n",
"uid = uuid.uuid4().hex\n",
"\n",
"file_name = raw_target.split(\"/\")[-1]\n",
"file_name = urllib.parse.unquote(file_name)\n",
"\n",
"with open(file_name, \"wb\") as f:\n",
" f.write(r.content)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.7"
},
"papermill": {
"default_parameters": {},
"environment_variables": {},
"parameters": {},
"version": "2.3.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}