<commit_before>---
layout: post
date: 2016-02-25 12:00
title: Writing an Activation Script
tag: "IT Ops"
comments: true
---

If you're interested in cryptocurrencies, you're probably periodically checking the prices of the most common currencies such as Bitcoin or Ether.
And if you're using [i3](https://i3wm.org/), you can monitor the prices directly in the i3 status line (see [i3blocks](https://github.com/vivien/i3blocks)). 
Even better, it appears to be extremely easy to do.

The first issue that we have to resolve is to figure out where to get the price.
Fortunately, Coinbase has an open API exactly for this.
In a generic form, the request looks like this:

```
https://api.coinbase.com/v2/prices/FROM-TO/spot
```

For example, if we would want to know the exchange rate of Bitcoin relative to US dollar, we would issue this command:

```bash
curl -sSL https://api.coinbase.com/v2/prices/BTC-USD/spot
```

It returns the following JSON string (I formatted it for clarity):

```
{
    "data":
        {
            "amount":"4278.01",
            "currency":"USD"
        },
    ...
}
```

Now, we'd want to have only the number in the bar, without all the redundant data.
For that, we can filter the result through SED:

```bash
$ curl -sSL https://api.coinbase.com/v2/prices/BTC-USD/spot | sed -r 's/[^0-9]*([0-9]+\.[0-9]+).*/BTC: \1$/g'
BTC: 4278.01$
```

Finally, for the price to show up on the i3 bar, we have to add this command to `i3block.conf`:

``` bash
# ~/.config/i3/i3blocks.conf
[btc]
command=curl -sSL https://api.coinbase.com/v2/prices/BTC-USD/spot | sed -r 's/[^0-9]*([0-9]+\.[0-9]+).*/BTC: \1$/g'
interval=100
label=BTC

[ether]
command=curl -sSL https://api.coinbase.com/v2/prices/ETH-USD/spot | sed -r 's/[^0-9]*([0-9]+\.[0-9]+).*/ETH: \1$/g'
interval=100
label=ETH
```

<commit_msg>a post on BTC prices in i3blocks<commit_after>---
layout: post
date: 2017-08-26 15:00
title: Displaying Coinbase prices in i3 status line
comments: true
---

If you're interested in cryptocurrencies, you're probably periodically checking the prices of the most common currencies such as Bitcoin or Ether.
And if you're using [i3](https://i3wm.org/), you can monitor the prices directly in the i3 status line (see [i3blocks](https://github.com/vivien/i3blocks)). 
Even better, it appears to be incredibly easy to do.

The first issue that we have to resolve is to figure out where to get the price.
Fortunately, Coinbase has an open API exactly for this.
In a generic form, the request looks like this:

```
https://api.coinbase.com/v2/prices/FROM-TO/spot
```

For example, if we would want to know the exchange rate of Bitcoin relative to US dollar, we would issue this command:

```bash
$ curl -sSL https://api.coinbase.com/v2/prices/BTC-USD/spot
```

It returns the following JSON string (I formatted it for clarity):

```
{
    "data":
        {
            "amount":"4278.01",
            "currency":"USD"
        },
}
```

Now, we'd want to have only the number in the status line, without all the redundant data.
For that, we can filter the result through SED:

```
$ curl -sSL https://api.coinbase.com/v2/prices/BTC-USD/spot | sed -r 's/[^0-9]*([0-9]+\.[0-9]+).*/BTC: \1$/g'
BTC: 4278.01$
```

Finally, for the price to show up on the i3 bar, we have to add this command to `i3block.conf`:

``` bash
# ~/.config/i3/i3blocks.conf
[btc]
command=curl -sSL https://api.coinbase.com/v2/prices/BTC-USD/spot | sed -r 's/[^0-9]*([0-9]+\.[0-9]+).*/BTC: \1$/g'
interval=100
label=BTC

[ether]
command=curl -sSL https://api.coinbase.com/v2/prices/ETH-USD/spot | sed -r 's/[^0-9]*([0-9]+\.[0-9]+).*/ETH: \1$/g'
interval=100
label=ETH
```


{'fraction_non_alphanumeric': 0.15597587719298245, 'fraction_numerical': 0.03618421052631579, 'mean_word_length': 3.401688781664656, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7034751', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1269, 'n_words': 440}