Skip to content

Commit

Permalink
Merge pull request #4 from trallard/dev
Browse files Browse the repository at this point in the history
Release 1.0.3
  • Loading branch information
trallard authored Apr 28, 2020
2 parents 83c0d0c + 49b1237 commit a5c8aef
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 18 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
# Change Log
All notable changes to the "pitaya-smoothie" extension will be documented in this file.

## RELEASE: 1.0.3

![FIX](https://img.shields.io/badge/-FIX-gray.svg?colorB=FC427B)

> ✨ Changed comments foreground to increase the contrast ratio [`afe1c39`](https://github.com/trallard/pitaya_smoothie/commit/afe1c39)
![NEW](https://img.shields.io/badge/-NEW-gray.svg?colorB=12CBC4)

> 📦 Add support for Restructuredtext [33bd1bd](https://github.com/trallard/pitaya_smoothie/commit/33bd1bd) <br>
> 📦 Add active tab border colour [e42baea](https://github.com/trallard/pitaya_smoothie/commit/e42baea)
## RELEASE: 1.0.2

![FIX](https://img.shields.io/badge/-FIX-gray.svg?colorB=FC427B)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

![License](https://img.shields.io/badge/License-BSD%203--Clause-gray.svg?colorA=2D2A56&colorB=7A76C2&style=flat.svg)
[![Version](https://vsmarketplacebadge.apphb.com/version/trallard.pitaya-smoothie.svg?subject=Pitaya%20Smoothie&colorA=2D2A56&colorB=7A76C2&style=flat.svg)](https://marketplace.visualstudio.com/items?itemName=trallard.pitaya-smoothie)
![GH actions](https://github.com/trallard/pitaya_smoothie/workflows/Publish%20release/badge.svg)


<table width='100%' align="center">
<tr>
Expand Down Expand Up @@ -54,7 +54,7 @@ I also made decisions to allow for meaningful contrast for reading comprehension
| -------------- | -------------------------------------------------------------------- |
| Background | ![#181036](https://placehold.it/15/181036/000000?text=%20) `#181036` |
| Foreground | ![#fefeff](https://placehold.it/15/fefeff/000000?text=%20) `#fefeff` |
| Comment | ![#5C588A](https://placehold.it/15/5C588A/000000?text=%20) `#5C588A` |
| Comment | ![#7E7AAA](https://placehold.it/15/7E7AAA/000000?text=%20) `#5C588A` |
| Keyword | ![#f62196](https://placehold.it/15/f62196/000000?text=%20) `#f62196` |
| String | ![#7998F2](https://placehold.it/15/7998F2/000000?text=%20) `#7998F2` |
| Number | ![#f3907e](https://placehold.it/15/f3907e/000000?text=%20) `#f3907e` |
Expand Down
156 changes: 156 additions & 0 deletions demo-scripts/rst.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
|pipe| Adding Blob storage bindings
====================================

You should now have a working function that collects data from the StackExchange API.

In this section, we will:

- Complete the function to store the data in AzureBlob storage
- Create a second function that identifies the addition of a file to Azure Blob storage and triggers a second function
- Create a database to store our cleaned data and modify the function to store the database

.. tip:: The repository containing all the scripts and solutions to this tutorial can be found at `<https://github.com/trallard/pycon2020-azure-functions>`_.

👉🏼 The code for this section is located in `<https://github.com/trallard/pycon2020-azure-functions/tree/master/solutions/02-timer-function-Blob-binding>`_


|light| Triggers and bindings
--------------------------------

- **Triggers**: these cause a function to run. They can be an HTTP request, a queue message or an event grid. Each function **must** have one trigger.

- **Binding**: is a connection between a function and another resource or function. They can be *input bindings, output bindings* or both. These are optional, and a function can have one or more bindings.

1. Create Azure Blob Storage
******************************************

We already created a Storage Account in the :ref:`deployfn` section. The next step is to create a Blob Storage container so we can start saving the data collected through your function.

#. Head over to |azureportal| and click on **Storage accounts** on the left sidebar and then on your function storage account.

.. image:: _static/images/snaps/storagedashboard.png
:align: center
:alt: Storager dashboard

#. Click on either of the **Containers** section (see image).

.. image:: _static/images/snaps/containers.png
:align: center
:alt: Containers screenshot

#. Click on **+ Container** at the top of the bar and provide a name for your Blob container.

#. Without leaving your dashboard, click on **Access keys** on the sidebar menu and copy the Connection string.

.. image:: _static/images/snaps/access.png
:align: center
:alt: Storage dashboard access

.. _attachblob:

2. Attach Blob binding
******************************************

Now that you created the Blob container, you need to add the binding to your function.

1. Back in VS Code click on the **Azure** extension on the sidebar and then right-click on your function name > **Add binding**.
2. Since we want to store the outputs in the container, we need to select the **OUT** direction followed by **Azure Blob Storage**.
3. Assign a name for the binding a path for the blob:

.. code-block::
functionblob/{DateTime}.csv
Notice that I am using the name of the container I created before and the binding expression ``DateTime`` which resolves to ``DateTime.UtcNow``. The following blob path in a ``function.json`` file creates a blob with a name like ``2020-04-16T17-59-55Z.txt``.

4. Select **AzureWebJobsStorage** for your local settings.

Once completed, your ``function.json`` file should look like this:

.. literalinclude:: ../solutions/02-timer-function-Blob-binding/timer-function/function.json
:language: json
:caption: function.json


5. Add the **Storage access key** that you copied before to your ``local.settings.json``. If you added your storage account through the Azure functions extensions, this should already be populated.

.. code-block::
:caption: local.settings.json
:emphasize-lines: 4
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": <Your key>,
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobs.timer-function.Disabled": "false"
}
}
.. _blobfunction:

3. Update your function
*****************************

We now need to update the function so that:

- Save the collected API items in a CSV file
- Store the file in the Blob container

Updating the `main_function.py` file:

.. literalinclude:: ../solutions/02-timer-function-Blob-binding/timer-function/main_function.py
:language: python
:caption: main_function.py
:emphasize-lines: 7, 33-53, 61-63, 87-93

Notice these lines in the above code:

.. code-block:: python
def main(
mytimer: func.TimerRequest,
outputBlob: func.Out[bytes],
context: func.Context
) -> None:
The ``outputBlob: func.Out[bytes]`` specifies the binding we just created and ``context: func.Context`` allows the function to get the context from the `host.json` file.

And also the script to access the StackExchange API:

.. literalinclude:: ../solutions/02-timer-function-Blob-binding/timer-function/utils/stack.py
:language: python
:caption: utils/stack.py

If you want, you can follow the steps in section :ref:`localdebug` to run and debug your function locally.

Otherwise, you can deploy and execute your function as we did in section :ref:`deployandrun` (except for the variables setting section as your storage details should be there already).


.. tip:: When deploying your function, you can click on the pop-up window **output window** link to track the deployment status/progress.

.. image:: _static/images/snaps/explore.png
:align: center
:alt: Explore deploy

After running your function you can head over to **Storage accounts > <your account> > Containers** and click on your function Blob container.

If all runs smoothly, you should be able to see the created file.

.. image:: _static/images/snaps/blob_file.png
:align: center
:alt: Blob file



|floppy| Additional resources and docs
---------------------------------------

- `ARM template for Blob Storage container <https://github.com/trallard/pycon2020-azure-functions/tree/master/storage-blob-container>`_
- `Azure functions triggers and bindings <https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings?WT.mc_id=pycon_tutorial-github-taallard>`_
- `Azure functions supported bindings <https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings#supported-bindings?WT.mc_id=pycon_tutorial-github-taallard>`_
- `Azure Storage documentation <http://azure.microsoft.com/documentation/articles/storage-create-storage-account?WT.mc_id=pycon_tutorial-github-taallard>`_
- `Binding expressions docs <https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-expressions-patterns?WT.mc_id=pycon_tutorial-github-taallard>`_
- `Azure function reference output <https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python#outputs?WT.mc_id=pycon_tutorial-github-taallard>`_
- `Python type hints cheatsheet <https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html>`_
91 changes: 87 additions & 4 deletions themes/Pitaya smoothie-color-theme-noitalic.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"tab.inactiveBackground": "#1f1445",
"tab.activeForeground": "#9491ce",
"tab.inactiveForeground": "#484f7d",
"tab.activeBorder": "#31E6E6",
// Title bar
"titleBar.activeBackground": "#1E1E3F",
"titleBar.activeForeground": "#789EF8",
Expand Down Expand Up @@ -538,7 +539,7 @@
"name": "Double-Slashed Comment",
"scope": "comment.line.double-slash",
"settings": {
"foreground": "#5C588A"
"foreground": "#7E7AAA"
}
},
{
Expand Down Expand Up @@ -1034,7 +1035,7 @@
"comment.block.html"
],
"settings": {
"foreground": "#5C588A"
"foreground": "#7E7AAA"
}
},
// JSON
Expand Down Expand Up @@ -1130,7 +1131,7 @@
"meta.diff.header.from-file"
],
"settings": {
"foreground": "#5C588A"
"foreground": "#7E7AAA"
}
},
{
Expand Down Expand Up @@ -1342,7 +1343,7 @@
"punctuation.definition.comment"
],
"settings": {
"foreground": "#5C588A"
"foreground": "#7E7AAA"
}
},
{
Expand Down Expand Up @@ -1513,6 +1514,88 @@
"foreground": "#C4A2F5"
}
},
// RST
{
"name": "RST - punctuation",
"scope": [
"punctuation.definition.heading.restructuredtext",
"markup.heading.restructuredtxt",
],
"settings": {
"foreground": "#82b1ff",
}
},
{
"name": "RST - directives",
"scope": [
"support.directive.restructuredtext"
],
"settings": {
"foreground": "#7ef3ca",
}
},
{
"name": "RST - substitutions",
"scope": [
"markup.underline.substitution.restructuredtext",
"markup.underline.link",
"punctuation.definition.substitution.restructuredtext"
],
"settings": {
"foreground": "#66E9EC",
}
},
{
"name": "RST - references",
"scope": [
"entity.name"
],
"settings": {
"foreground": "#A599E9",
}
},
{
"name": "RST - lists",
"scope": [
"markup.list.restructuredtext",
"beginning.punctuation.definition.list.restructuredtext",
"punctuation.definition.list.begin.restructuredtext",
"markup.list.unnumbered.restructuredtext",
"markup.list.numbered.restructuredtext",
],
"settings": {
"foreground": "#82b1ff",
}
},
{
"name": "RST - bold",
"scope": [
"markup.bold.restructuredtext"
],
"settings": {
"foreground": "#F3CA7E",
"fontStyle": "bold"
}
},
{
"name": "RST -inline code",
"scope": [
"markup.inline.raw.string.restructuredtext",
"punctuation.definition.raw.restructuredtext",
"markup.raw.restructuredtext"
],
"settings": {
"foreground": "#A599E9",
}
},
{
"name": "RST - Color for Emphasis Italic",
"scope": "markup.italic.restructuredtext",
"settings": {
"fontStyle": "italic",
"foreground": "#b07afc"
}
},
// SASS
{
"name": "SCSS Variable",
Expand Down
Loading

0 comments on commit a5c8aef

Please sign in to comment.