From e6a9fb93460bad332e7576a8baf0d5517b764837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Wed, 11 Oct 2023 11:14:25 +0200 Subject: [PATCH] Update documentation --- articles.html | 7 ++-- articles10.html | 7 ++-- articles11.html | 7 ++-- articles12.html | 7 ++-- articles13.html | 7 ++-- articles14.html | 7 ++-- articles15.html | 7 ++-- articles16.html | 7 ++-- articles17.html | 7 ++-- articles18.html | 7 ++-- articles19.html | 7 ++-- articles2.html | 7 ++-- articles20.html | 7 ++-- articles21.html | 7 ++-- articles22.html | 7 ++-- articles23.html | 7 ++-- articles24.html | 7 ++-- articles25.html | 7 ++-- articles26.html | 7 ++-- articles27.html | 7 ++-- articles28.html | 7 ++-- articles29.html | 7 ++-- articles3.html | 7 ++-- articles30.html | 7 ++-- articles31.html | 7 ++-- articles32.html | 7 ++-- articles33.html | 7 ++-- articles34.html | 7 ++-- articles35.html | 7 ++-- articles36.html | 7 ++-- articles37.html | 7 ++-- articles38.html | 7 ++-- articles39.html | 7 ++-- articles4.html | 7 ++-- articles40.html | 7 ++-- articles41.html | 7 ++-- articles42.html | 7 ++-- articles43.html | 7 ++-- articles44.html | 7 ++-- articles45.html | 7 ++-- articles46.html | 7 ++-- articles47.html | 7 ++-- articles48.html | 7 ++-- articles49.html | 7 ++-- articles5.html | 7 ++-- articles50.html | 7 ++-- articles51.html | 7 ++-- articles52.html | 7 ++-- articles53.html | 7 ++-- articles54.html | 7 ++-- articles55.html | 7 ++-- articles6.html | 7 ++-- articles7.html | 7 ++-- articles8.html | 7 ++-- articles9.html | 7 ++-- author/.html | 7 ++-- author/.html10 | 7 ++-- author/.html11 | 7 ++-- author/.html12 | 7 ++-- author/.html13 | 7 ++-- author/.html14 | 7 ++-- author/.html15 | 7 ++-- author/.html16 | 7 ++-- author/.html17 | 7 ++-- author/.html18 | 7 ++-- author/.html19 | 7 ++-- author/.html2 | 7 ++-- author/.html20 | 7 ++-- author/.html21 | 7 ++-- author/.html22 | 7 ++-- author/.html23 | 7 ++-- author/.html24 | 7 ++-- author/.html25 | 7 ++-- author/.html26 | 7 ++-- author/.html27 | 7 ++-- author/.html28 | 7 ++-- author/.html29 | 7 ++-- author/.html3 | 7 ++-- author/.html30 | 7 ++-- author/.html31 | 7 ++-- author/.html32 | 7 ++-- author/.html33 | 7 ++-- author/.html34 | 7 ++-- author/.html35 | 7 ++-- author/.html36 | 7 ++-- author/.html37 | 7 ++-- author/.html38 | 7 ++-- author/.html39 | 7 ++-- author/.html4 | 7 ++-- author/.html40 | 7 ++-- author/.html41 | 7 ++-- author/.html42 | 7 ++-- author/.html43 | 7 ++-- author/.html44 | 7 ++-- author/.html45 | 7 ++-- author/.html46 | 7 ++-- author/.html47 | 7 ++-- author/.html48 | 7 ++-- author/.html49 | 7 ++-- author/.html5 | 7 ++-- author/.html50 | 7 ++-- author/.html6 | 7 ++-- author/.html7 | 7 ++-- author/.html8 | 7 ++-- author/.html9 | 7 ++-- code/index.html | 7 ++-- code/index10.html | 7 ++-- code/index11.html | 7 ++-- code/index12.html | 7 ++-- code/index13.html | 7 ++-- code/index14.html | 7 ++-- code/index15.html | 7 ++-- code/index16.html | 7 ++-- code/index17.html | 7 ++-- code/index18.html | 7 ++-- code/index19.html | 7 ++-- code/index2.html | 7 ++-- code/index20.html | 7 ++-- code/index21.html | 7 ++-- code/index22.html | 7 ++-- code/index3.html | 7 ++-- code/index4.html | 7 ++-- code/index5.html | 7 ++-- code/index6.html | 7 ++-- code/index7.html | 7 ++-- code/index8.html | 7 ++-- code/index9.html | 7 ++-- convert-string-to-duration.html | 54 ++++++++++++++--------------- feeds/.atom.xml | 61 +++++++++++++++++---------------- feeds/.rss.xml | 7 ++-- feeds/all-en.atom.xml | 61 +++++++++++++++++---------------- feeds/all.atom.xml | 61 +++++++++++++++++---------------- feeds/code.atom.xml | 61 +++++++++++++++++---------------- tag/conversion.html | 7 ++-- tag/python.html | 7 ++-- 135 files changed, 671 insertions(+), 537 deletions(-) diff --git a/articles.html b/articles.html index ffc6a41..abc896c 100644 --- a/articles.html +++ b/articles.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles10.html b/articles10.html index ffc6a41..abc896c 100644 --- a/articles10.html +++ b/articles10.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles11.html b/articles11.html index ffc6a41..abc896c 100644 --- a/articles11.html +++ b/articles11.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles12.html b/articles12.html index ffc6a41..abc896c 100644 --- a/articles12.html +++ b/articles12.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles13.html b/articles13.html index ffc6a41..abc896c 100644 --- a/articles13.html +++ b/articles13.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles14.html b/articles14.html index ffc6a41..abc896c 100644 --- a/articles14.html +++ b/articles14.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles15.html b/articles15.html index ffc6a41..abc896c 100644 --- a/articles15.html +++ b/articles15.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles16.html b/articles16.html index ffc6a41..abc896c 100644 --- a/articles16.html +++ b/articles16.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles17.html b/articles17.html index ffc6a41..abc896c 100644 --- a/articles17.html +++ b/articles17.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles18.html b/articles18.html index ffc6a41..abc896c 100644 --- a/articles18.html +++ b/articles18.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles19.html b/articles19.html index ffc6a41..abc896c 100644 --- a/articles19.html +++ b/articles19.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles2.html b/articles2.html index ffc6a41..abc896c 100644 --- a/articles2.html +++ b/articles2.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles20.html b/articles20.html index ffc6a41..abc896c 100644 --- a/articles20.html +++ b/articles20.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles21.html b/articles21.html index ffc6a41..abc896c 100644 --- a/articles21.html +++ b/articles21.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles22.html b/articles22.html index ffc6a41..abc896c 100644 --- a/articles22.html +++ b/articles22.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles23.html b/articles23.html index ffc6a41..abc896c 100644 --- a/articles23.html +++ b/articles23.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles24.html b/articles24.html index ffc6a41..abc896c 100644 --- a/articles24.html +++ b/articles24.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles25.html b/articles25.html index ffc6a41..abc896c 100644 --- a/articles25.html +++ b/articles25.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles26.html b/articles26.html index ffc6a41..abc896c 100644 --- a/articles26.html +++ b/articles26.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles27.html b/articles27.html index ffc6a41..abc896c 100644 --- a/articles27.html +++ b/articles27.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles28.html b/articles28.html index ffc6a41..abc896c 100644 --- a/articles28.html +++ b/articles28.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles29.html b/articles29.html index ffc6a41..abc896c 100644 --- a/articles29.html +++ b/articles29.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles3.html b/articles3.html index ffc6a41..abc896c 100644 --- a/articles3.html +++ b/articles3.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles30.html b/articles30.html index ffc6a41..abc896c 100644 --- a/articles30.html +++ b/articles30.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles31.html b/articles31.html index ffc6a41..abc896c 100644 --- a/articles31.html +++ b/articles31.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles32.html b/articles32.html index ffc6a41..abc896c 100644 --- a/articles32.html +++ b/articles32.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles33.html b/articles33.html index ffc6a41..abc896c 100644 --- a/articles33.html +++ b/articles33.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles34.html b/articles34.html index ffc6a41..abc896c 100644 --- a/articles34.html +++ b/articles34.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles35.html b/articles35.html index ffc6a41..abc896c 100644 --- a/articles35.html +++ b/articles35.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles36.html b/articles36.html index ffc6a41..abc896c 100644 --- a/articles36.html +++ b/articles36.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles37.html b/articles37.html index ffc6a41..abc896c 100644 --- a/articles37.html +++ b/articles37.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles38.html b/articles38.html index ffc6a41..abc896c 100644 --- a/articles38.html +++ b/articles38.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles39.html b/articles39.html index ffc6a41..abc896c 100644 --- a/articles39.html +++ b/articles39.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles4.html b/articles4.html index ffc6a41..abc896c 100644 --- a/articles4.html +++ b/articles4.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles40.html b/articles40.html index ffc6a41..abc896c 100644 --- a/articles40.html +++ b/articles40.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles41.html b/articles41.html index ffc6a41..abc896c 100644 --- a/articles41.html +++ b/articles41.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles42.html b/articles42.html index ffc6a41..abc896c 100644 --- a/articles42.html +++ b/articles42.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles43.html b/articles43.html index ffc6a41..abc896c 100644 --- a/articles43.html +++ b/articles43.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles44.html b/articles44.html index ffc6a41..abc896c 100644 --- a/articles44.html +++ b/articles44.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles45.html b/articles45.html index ffc6a41..abc896c 100644 --- a/articles45.html +++ b/articles45.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles46.html b/articles46.html index ffc6a41..abc896c 100644 --- a/articles46.html +++ b/articles46.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles47.html b/articles47.html index ffc6a41..abc896c 100644 --- a/articles47.html +++ b/articles47.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles48.html b/articles48.html index ffc6a41..abc896c 100644 --- a/articles48.html +++ b/articles48.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles49.html b/articles49.html index ffc6a41..abc896c 100644 --- a/articles49.html +++ b/articles49.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles5.html b/articles5.html index ffc6a41..abc896c 100644 --- a/articles5.html +++ b/articles5.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles50.html b/articles50.html index ffc6a41..abc896c 100644 --- a/articles50.html +++ b/articles50.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles51.html b/articles51.html index ffc6a41..abc896c 100644 --- a/articles51.html +++ b/articles51.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles52.html b/articles52.html index ffc6a41..abc896c 100644 --- a/articles52.html +++ b/articles52.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles53.html b/articles53.html index ffc6a41..abc896c 100644 --- a/articles53.html +++ b/articles53.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles54.html b/articles54.html index ffc6a41..abc896c 100644 --- a/articles54.html +++ b/articles54.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles55.html b/articles55.html index ffc6a41..abc896c 100644 --- a/articles55.html +++ b/articles55.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles6.html b/articles6.html index ffc6a41..abc896c 100644 --- a/articles6.html +++ b/articles6.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles7.html b/articles7.html index ffc6a41..abc896c 100644 --- a/articles7.html +++ b/articles7.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles8.html b/articles8.html index ffc6a41..abc896c 100644 --- a/articles8.html +++ b/articles8.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/articles9.html b/articles9.html index ffc6a41..abc896c 100644 --- a/articles9.html +++ b/articles9.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html b/author/.html index ee0bbda..a86ad32 100644 --- a/author/.html +++ b/author/.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html10 b/author/.html10 index ee0bbda..a86ad32 100644 --- a/author/.html10 +++ b/author/.html10 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html11 b/author/.html11 index ee0bbda..a86ad32 100644 --- a/author/.html11 +++ b/author/.html11 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html12 b/author/.html12 index ee0bbda..a86ad32 100644 --- a/author/.html12 +++ b/author/.html12 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html13 b/author/.html13 index ee0bbda..a86ad32 100644 --- a/author/.html13 +++ b/author/.html13 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html14 b/author/.html14 index ee0bbda..a86ad32 100644 --- a/author/.html14 +++ b/author/.html14 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html15 b/author/.html15 index ee0bbda..a86ad32 100644 --- a/author/.html15 +++ b/author/.html15 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html16 b/author/.html16 index ee0bbda..a86ad32 100644 --- a/author/.html16 +++ b/author/.html16 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html17 b/author/.html17 index ee0bbda..a86ad32 100644 --- a/author/.html17 +++ b/author/.html17 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html18 b/author/.html18 index ee0bbda..a86ad32 100644 --- a/author/.html18 +++ b/author/.html18 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html19 b/author/.html19 index ee0bbda..a86ad32 100644 --- a/author/.html19 +++ b/author/.html19 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html2 b/author/.html2 index ee0bbda..a86ad32 100644 --- a/author/.html2 +++ b/author/.html2 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html20 b/author/.html20 index ee0bbda..a86ad32 100644 --- a/author/.html20 +++ b/author/.html20 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html21 b/author/.html21 index ee0bbda..a86ad32 100644 --- a/author/.html21 +++ b/author/.html21 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html22 b/author/.html22 index ee0bbda..a86ad32 100644 --- a/author/.html22 +++ b/author/.html22 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html23 b/author/.html23 index ee0bbda..a86ad32 100644 --- a/author/.html23 +++ b/author/.html23 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html24 b/author/.html24 index ee0bbda..a86ad32 100644 --- a/author/.html24 +++ b/author/.html24 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html25 b/author/.html25 index ee0bbda..a86ad32 100644 --- a/author/.html25 +++ b/author/.html25 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html26 b/author/.html26 index ee0bbda..a86ad32 100644 --- a/author/.html26 +++ b/author/.html26 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html27 b/author/.html27 index ee0bbda..a86ad32 100644 --- a/author/.html27 +++ b/author/.html27 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html28 b/author/.html28 index ee0bbda..a86ad32 100644 --- a/author/.html28 +++ b/author/.html28 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html29 b/author/.html29 index ee0bbda..a86ad32 100644 --- a/author/.html29 +++ b/author/.html29 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html3 b/author/.html3 index ee0bbda..a86ad32 100644 --- a/author/.html3 +++ b/author/.html3 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html30 b/author/.html30 index ee0bbda..a86ad32 100644 --- a/author/.html30 +++ b/author/.html30 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html31 b/author/.html31 index ee0bbda..a86ad32 100644 --- a/author/.html31 +++ b/author/.html31 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html32 b/author/.html32 index ee0bbda..a86ad32 100644 --- a/author/.html32 +++ b/author/.html32 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html33 b/author/.html33 index ee0bbda..a86ad32 100644 --- a/author/.html33 +++ b/author/.html33 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html34 b/author/.html34 index ee0bbda..a86ad32 100644 --- a/author/.html34 +++ b/author/.html34 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html35 b/author/.html35 index ee0bbda..a86ad32 100644 --- a/author/.html35 +++ b/author/.html35 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html36 b/author/.html36 index ee0bbda..a86ad32 100644 --- a/author/.html36 +++ b/author/.html36 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html37 b/author/.html37 index ee0bbda..a86ad32 100644 --- a/author/.html37 +++ b/author/.html37 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html38 b/author/.html38 index ee0bbda..a86ad32 100644 --- a/author/.html38 +++ b/author/.html38 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html39 b/author/.html39 index ee0bbda..a86ad32 100644 --- a/author/.html39 +++ b/author/.html39 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html4 b/author/.html4 index ee0bbda..a86ad32 100644 --- a/author/.html4 +++ b/author/.html4 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html40 b/author/.html40 index ee0bbda..a86ad32 100644 --- a/author/.html40 +++ b/author/.html40 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html41 b/author/.html41 index ee0bbda..a86ad32 100644 --- a/author/.html41 +++ b/author/.html41 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html42 b/author/.html42 index ee0bbda..a86ad32 100644 --- a/author/.html42 +++ b/author/.html42 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html43 b/author/.html43 index ee0bbda..a86ad32 100644 --- a/author/.html43 +++ b/author/.html43 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html44 b/author/.html44 index ee0bbda..a86ad32 100644 --- a/author/.html44 +++ b/author/.html44 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html45 b/author/.html45 index ee0bbda..a86ad32 100644 --- a/author/.html45 +++ b/author/.html45 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html46 b/author/.html46 index ee0bbda..a86ad32 100644 --- a/author/.html46 +++ b/author/.html46 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html47 b/author/.html47 index ee0bbda..a86ad32 100644 --- a/author/.html47 +++ b/author/.html47 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html48 b/author/.html48 index ee0bbda..a86ad32 100644 --- a/author/.html48 +++ b/author/.html48 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html49 b/author/.html49 index ee0bbda..a86ad32 100644 --- a/author/.html49 +++ b/author/.html49 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html5 b/author/.html5 index ee0bbda..a86ad32 100644 --- a/author/.html5 +++ b/author/.html5 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html50 b/author/.html50 index ee0bbda..a86ad32 100644 --- a/author/.html50 +++ b/author/.html50 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html6 b/author/.html6 index ee0bbda..a86ad32 100644 --- a/author/.html6 +++ b/author/.html6 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html7 b/author/.html7 index ee0bbda..a86ad32 100644 --- a/author/.html7 +++ b/author/.html7 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html8 b/author/.html8 index ee0bbda..a86ad32 100644 --- a/author/.html8 +++ b/author/.html8 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/author/.html9 b/author/.html9 index ee0bbda..a86ad32 100644 --- a/author/.html9 +++ b/author/.html9 @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/code/index.html b/code/index.html index 547f23d..0ba03b3 100644 --- a/code/index.html +++ b/code/index.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index10.html b/code/index10.html index 547f23d..0ba03b3 100644 --- a/code/index10.html +++ b/code/index10.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index11.html b/code/index11.html index 547f23d..0ba03b3 100644 --- a/code/index11.html +++ b/code/index11.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index12.html b/code/index12.html index 547f23d..0ba03b3 100644 --- a/code/index12.html +++ b/code/index12.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index13.html b/code/index13.html index 547f23d..0ba03b3 100644 --- a/code/index13.html +++ b/code/index13.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index14.html b/code/index14.html index 547f23d..0ba03b3 100644 --- a/code/index14.html +++ b/code/index14.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index15.html b/code/index15.html index 547f23d..0ba03b3 100644 --- a/code/index15.html +++ b/code/index15.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index16.html b/code/index16.html index 547f23d..0ba03b3 100644 --- a/code/index16.html +++ b/code/index16.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index17.html b/code/index17.html index 547f23d..0ba03b3 100644 --- a/code/index17.html +++ b/code/index17.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index18.html b/code/index18.html index 547f23d..0ba03b3 100644 --- a/code/index18.html +++ b/code/index18.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index19.html b/code/index19.html index 547f23d..0ba03b3 100644 --- a/code/index19.html +++ b/code/index19.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index2.html b/code/index2.html index 547f23d..0ba03b3 100644 --- a/code/index2.html +++ b/code/index2.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index20.html b/code/index20.html index 547f23d..0ba03b3 100644 --- a/code/index20.html +++ b/code/index20.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index21.html b/code/index21.html index 547f23d..0ba03b3 100644 --- a/code/index21.html +++ b/code/index21.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index22.html b/code/index22.html index 547f23d..0ba03b3 100644 --- a/code/index22.html +++ b/code/index22.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index3.html b/code/index3.html index 547f23d..0ba03b3 100644 --- a/code/index3.html +++ b/code/index3.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index4.html b/code/index4.html index 547f23d..0ba03b3 100644 --- a/code/index4.html +++ b/code/index4.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index5.html b/code/index5.html index 547f23d..0ba03b3 100644 --- a/code/index5.html +++ b/code/index5.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index6.html b/code/index6.html index 547f23d..0ba03b3 100644 --- a/code/index6.html +++ b/code/index6.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index7.html b/code/index7.html index 547f23d..0ba03b3 100644 --- a/code/index7.html +++ b/code/index7.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index8.html b/code/index8.html index 547f23d..0ba03b3 100644 --- a/code/index8.html +++ b/code/index8.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/code/index9.html b/code/index9.html index 547f23d..0ba03b3 100644 --- a/code/index9.html +++ b/code/index9.html @@ -42,9 +42,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …

python, conversion
diff --git a/convert-string-to-duration.html b/convert-string-to-duration.html index b777851..df5f39d 100644 --- a/convert-string-to-duration.html +++ b/convert-string-to-duration.html @@ -40,37 +40,37 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration(value: str, target: Literal[“days”, “hours”]): - “”“Convert a string to a number of hours, or days”“” - num = int(“”.join(filter(str.isdigit, value)))

-
if target == "hours":
-    reconvert = True
+
from typing import Literal
 
-if "h" in value:
-    if target == "days":
-        raise ValueError("Invalid duration value", value)
-    num = num
-    reconvert = False
-elif "d" in value:
-    num = num
-elif "w" in value:
-    num = num * 7
-elif "m" in value:
-    num = num * 30
-elif "y" in value:
-    num = num * 365
-else:
-    raise ValueError("Invalid duration value", value)
 
-if target == "hours" and reconvert:
-    num = num * 24
+def string_to_duration(value: str, target: Literal["days", "hours"]):
+    """Convert a string to a number of hours, or days"""
+    num = int("".join(filter(str.isdigit, value)))
 
-return num
+    if target == "hours":
+        reconvert = True
+
+    if "h" in value:
+        if target == "days":
+            raise ValueError("Invalid duration value", value)
+        num = num
+        reconvert = False
+    elif "d" in value:
+        num = num
+    elif "w" in value:
+        num = num * 7
+    elif "m" in value:
+        num = num * 30
+    elif "y" in value:
+        num = num * 365
+    else:
+        raise ValueError("Invalid duration value", value)
+
+    if target == "hours" and reconvert:
+        num = num * 24
+
+    return num
 
- -

““

#python, #conversion - Posté dans la catégorie code

diff --git a/feeds/.atom.xml b/feeds/.atom.xml index 5b0e042..95cf4f1 100644 --- a/feeds/.atom.xml +++ b/feeds/.atom.xml @@ -7,9 +7,10 @@ </code></pre></div> <p>The code&nbsp;:</p> -<p><span class="dquo">&#8220;</span>`python -from typing import&nbsp;Literal</p> -<p>def string_to_duration …</p><p>I found myself wanting to convert a string to a duration (int), for some&nbsp;configuration.</p> +<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span> + + +<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value …</span></code></pre></div><p>I found myself wanting to convert a string to a duration (int), for some&nbsp;configuration.</p> <p>Something you can call like&nbsp;this:</p> <div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">&quot;1d&quot;</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">&quot;days&quot;</span><span class="p">)</span> <span class="c1"># returns 1</span> <span class="n">string_to_duration</span><span class="p">(</span><span class="s2">&quot;1d&quot;</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">&quot;hours&quot;</span><span class="p">)</span> <span class="c1"># returns 24</span> @@ -17,37 +18,37 @@ from typing import&nbsp;Literal</p> </code></pre></div> <p>The code&nbsp;:</p> -<p><span class="dquo">&#8220;</span>`python -from typing import&nbsp;Literal</p> -<p>def string_to_duration(value: str, target: Literal[&#8220;days&#8221;, &#8220;hours&#8221;]): - &#8220;&#8221;&#8220;Convert a string to a number of hours, or days&#8221;&#8220;&#8221; - num = int(&#8220;&#8221;.join(filter(str.isdigit,&nbsp;value)))</p> -<div class="highlight"><pre><span></span><code><span class="k">if</span><span class="w"> </span><span class="nv">target</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">&quot;hours&quot;</span>: -<span class="w"> </span><span class="nv">reconvert</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">True</span> +<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span> -<span class="k">if</span><span class="w"> </span><span class="s2">&quot;h&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="nv">target</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">&quot;days&quot;</span>: -<span class="w"> </span><span class="nv">raise</span><span class="w"> </span><span class="nv">ValueError</span><span class="ss">(</span><span class="s2">&quot;Invalid duration value&quot;</span>,<span class="w"> </span><span class="nv">value</span><span class="ss">)</span> -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span> -<span class="w"> </span><span class="nv">reconvert</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">False</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;d&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;w&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">7</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;m&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">30</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;y&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">365</span> -<span class="k">else</span>: -<span class="w"> </span><span class="nv">raise</span><span class="w"> </span><span class="nv">ValueError</span><span class="ss">(</span><span class="s2">&quot;Invalid duration value&quot;</span>,<span class="w"> </span><span class="nv">value</span><span class="ss">)</span> -<span class="k">if</span><span class="w"> </span><span class="nv">target</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">&quot;hours&quot;</span><span class="w"> </span><span class="nv">and</span><span class="w"> </span><span class="nv">reconvert</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">24</span> +<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;days&quot;</span><span class="p">,</span> <span class="s2">&quot;hours&quot;</span><span class="p">]):</span> +<span class="w"> </span><span class="sd">&quot;&quot;&quot;Convert a string to a number of hours, or days&quot;&quot;&quot;</span> + <span class="n">num</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">,</span> <span class="n">value</span><span class="p">)))</span> -<span class="k">return</span><span class="w"> </span><span class="nv">num</span> -</code></pre></div> + <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">&quot;hours&quot;</span><span class="p">:</span> + <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">True</span> -<p><span class="dquo">&#8220;</span>&#8220;&#8220;</p>2023, Semaine 402023-10-08T00:00:00+02:002023-10-08T00:00:00+02:00tag:blog.notmyidea.org,2023-10-08:/2023-semaine-40.html + <span class="k">if</span> <span class="s2">&quot;h&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">&quot;days&quot;</span><span class="p">:</span> + <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid duration value&quot;</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> + <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">False</span> + <span class="k">elif</span> <span class="s2">&quot;d&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> + <span class="k">elif</span> <span class="s2">&quot;w&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">7</span> + <span class="k">elif</span> <span class="s2">&quot;m&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">30</span> + <span class="k">elif</span> <span class="s2">&quot;y&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">365</span> + <span class="k">else</span><span class="p">:</span> + <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid duration value&quot;</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> + + <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">&quot;hours&quot;</span> <span class="ow">and</span> <span class="n">reconvert</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">24</span> + + <span class="k">return</span> <span class="n">num</span> +</code></pre></div>2023, Semaine 402023-10-08T00:00:00+02:002023-10-08T00:00:00+02:00tag:blog.notmyidea.org,2023-10-08:/2023-semaine-40.html <p>Je me suis réservé les matins pour travailler, et je suis content du rythme que ça à donné à ma semaine. C&#8217;était aussi le retour des pomodoros&nbsp;!</p> <h2 id="ce-qui-sest-passe">Ce qui s&#8217;est&nbsp;passé</h2> <dl> diff --git a/feeds/.rss.xml b/feeds/.rss.xml index 2e4bf02..7bafedc 100644 --- a/feeds/.rss.xml +++ b/feeds/.rss.xml @@ -7,9 +7,10 @@ </code></pre></div> <p>The code&nbsp;:</p> -<p><span class="dquo">&#8220;</span>`python -from typing import&nbsp;Literal</p> -<p>def string_to_duration …</p>Wed, 11 Oct 2023 00:00:00 +0200tag:blog.notmyidea.org,2023-10-11:/convert-string-to-duration.htmlcodepythonconversion2023, Semaine 40https://blog.notmyidea.org/2023-semaine-40.html +<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span> + + +<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value …</span></code></pre></div>Wed, 11 Oct 2023 00:00:00 +0200tag:blog.notmyidea.org,2023-10-11:/convert-string-to-duration.htmlcodepythonconversion2023, Semaine 40https://blog.notmyidea.org/2023-semaine-40.html <p>Je me suis réservé les matins pour travailler, et je suis content du rythme que ça à donné à ma semaine. C&#8217;était aussi le retour des pomodoros&nbsp;!</p> <h2 id="ce-qui-sest-passe">Ce qui s&#8217;est&nbsp;passé</h2> <dl> diff --git a/feeds/all-en.atom.xml b/feeds/all-en.atom.xml index e293fa7..d4d7ad7 100644 --- a/feeds/all-en.atom.xml +++ b/feeds/all-en.atom.xml @@ -7,9 +7,10 @@ </code></pre></div> <p>The code&nbsp;:</p> -<p><span class="dquo">&#8220;</span>`python -from typing import&nbsp;Literal</p> -<p>def string_to_duration …</p><p>I found myself wanting to convert a string to a duration (int), for some&nbsp;configuration.</p> +<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span> + + +<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value …</span></code></pre></div><p>I found myself wanting to convert a string to a duration (int), for some&nbsp;configuration.</p> <p>Something you can call like&nbsp;this:</p> <div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">&quot;1d&quot;</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">&quot;days&quot;</span><span class="p">)</span> <span class="c1"># returns 1</span> <span class="n">string_to_duration</span><span class="p">(</span><span class="s2">&quot;1d&quot;</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">&quot;hours&quot;</span><span class="p">)</span> <span class="c1"># returns 24</span> @@ -17,37 +18,37 @@ from typing import&nbsp;Literal</p> </code></pre></div> <p>The code&nbsp;:</p> -<p><span class="dquo">&#8220;</span>`python -from typing import&nbsp;Literal</p> -<p>def string_to_duration(value: str, target: Literal[&#8220;days&#8221;, &#8220;hours&#8221;]): - &#8220;&#8221;&#8220;Convert a string to a number of hours, or days&#8221;&#8220;&#8221; - num = int(&#8220;&#8221;.join(filter(str.isdigit,&nbsp;value)))</p> -<div class="highlight"><pre><span></span><code><span class="k">if</span><span class="w"> </span><span class="nv">target</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">&quot;hours&quot;</span>: -<span class="w"> </span><span class="nv">reconvert</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">True</span> +<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span> -<span class="k">if</span><span class="w"> </span><span class="s2">&quot;h&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="nv">target</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">&quot;days&quot;</span>: -<span class="w"> </span><span class="nv">raise</span><span class="w"> </span><span class="nv">ValueError</span><span class="ss">(</span><span class="s2">&quot;Invalid duration value&quot;</span>,<span class="w"> </span><span class="nv">value</span><span class="ss">)</span> -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span> -<span class="w"> </span><span class="nv">reconvert</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">False</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;d&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;w&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">7</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;m&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">30</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;y&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">365</span> -<span class="k">else</span>: -<span class="w"> </span><span class="nv">raise</span><span class="w"> </span><span class="nv">ValueError</span><span class="ss">(</span><span class="s2">&quot;Invalid duration value&quot;</span>,<span class="w"> </span><span class="nv">value</span><span class="ss">)</span> -<span class="k">if</span><span class="w"> </span><span class="nv">target</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">&quot;hours&quot;</span><span class="w"> </span><span class="nv">and</span><span class="w"> </span><span class="nv">reconvert</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">24</span> +<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;days&quot;</span><span class="p">,</span> <span class="s2">&quot;hours&quot;</span><span class="p">]):</span> +<span class="w"> </span><span class="sd">&quot;&quot;&quot;Convert a string to a number of hours, or days&quot;&quot;&quot;</span> + <span class="n">num</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">,</span> <span class="n">value</span><span class="p">)))</span> -<span class="k">return</span><span class="w"> </span><span class="nv">num</span> -</code></pre></div> + <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">&quot;hours&quot;</span><span class="p">:</span> + <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">True</span> -<p><span class="dquo">&#8220;</span>&#8220;&#8220;</p>2023, Semaine 402023-10-08T00:00:00+02:002023-10-08T00:00:00+02:00tag:blog.notmyidea.org,2023-10-08:/2023-semaine-40.html + <span class="k">if</span> <span class="s2">&quot;h&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">&quot;days&quot;</span><span class="p">:</span> + <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid duration value&quot;</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> + <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">False</span> + <span class="k">elif</span> <span class="s2">&quot;d&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> + <span class="k">elif</span> <span class="s2">&quot;w&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">7</span> + <span class="k">elif</span> <span class="s2">&quot;m&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">30</span> + <span class="k">elif</span> <span class="s2">&quot;y&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">365</span> + <span class="k">else</span><span class="p">:</span> + <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid duration value&quot;</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> + + <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">&quot;hours&quot;</span> <span class="ow">and</span> <span class="n">reconvert</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">24</span> + + <span class="k">return</span> <span class="n">num</span> +</code></pre></div>2023, Semaine 402023-10-08T00:00:00+02:002023-10-08T00:00:00+02:00tag:blog.notmyidea.org,2023-10-08:/2023-semaine-40.html <p>Je me suis réservé les matins pour travailler, et je suis content du rythme que ça à donné à ma semaine. C&#8217;était aussi le retour des pomodoros&nbsp;!</p> <h2 id="ce-qui-sest-passe">Ce qui s&#8217;est&nbsp;passé</h2> <dl> diff --git a/feeds/all.atom.xml b/feeds/all.atom.xml index 761044a..74bd02a 100644 --- a/feeds/all.atom.xml +++ b/feeds/all.atom.xml @@ -7,9 +7,10 @@ </code></pre></div> <p>The code&nbsp;:</p> -<p><span class="dquo">&#8220;</span>`python -from typing import&nbsp;Literal</p> -<p>def string_to_duration …</p><p>I found myself wanting to convert a string to a duration (int), for some&nbsp;configuration.</p> +<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span> + + +<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value …</span></code></pre></div><p>I found myself wanting to convert a string to a duration (int), for some&nbsp;configuration.</p> <p>Something you can call like&nbsp;this:</p> <div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">&quot;1d&quot;</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">&quot;days&quot;</span><span class="p">)</span> <span class="c1"># returns 1</span> <span class="n">string_to_duration</span><span class="p">(</span><span class="s2">&quot;1d&quot;</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">&quot;hours&quot;</span><span class="p">)</span> <span class="c1"># returns 24</span> @@ -17,37 +18,37 @@ from typing import&nbsp;Literal</p> </code></pre></div> <p>The code&nbsp;:</p> -<p><span class="dquo">&#8220;</span>`python -from typing import&nbsp;Literal</p> -<p>def string_to_duration(value: str, target: Literal[&#8220;days&#8221;, &#8220;hours&#8221;]): - &#8220;&#8221;&#8220;Convert a string to a number of hours, or days&#8221;&#8220;&#8221; - num = int(&#8220;&#8221;.join(filter(str.isdigit,&nbsp;value)))</p> -<div class="highlight"><pre><span></span><code><span class="k">if</span><span class="w"> </span><span class="nv">target</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">&quot;hours&quot;</span>: -<span class="w"> </span><span class="nv">reconvert</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">True</span> +<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span> -<span class="k">if</span><span class="w"> </span><span class="s2">&quot;h&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="nv">target</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">&quot;days&quot;</span>: -<span class="w"> </span><span class="nv">raise</span><span class="w"> </span><span class="nv">ValueError</span><span class="ss">(</span><span class="s2">&quot;Invalid duration value&quot;</span>,<span class="w"> </span><span class="nv">value</span><span class="ss">)</span> -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span> -<span class="w"> </span><span class="nv">reconvert</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">False</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;d&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;w&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">7</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;m&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">30</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;y&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">365</span> -<span class="k">else</span>: -<span class="w"> </span><span class="nv">raise</span><span class="w"> </span><span class="nv">ValueError</span><span class="ss">(</span><span class="s2">&quot;Invalid duration value&quot;</span>,<span class="w"> </span><span class="nv">value</span><span class="ss">)</span> -<span class="k">if</span><span class="w"> </span><span class="nv">target</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">&quot;hours&quot;</span><span class="w"> </span><span class="nv">and</span><span class="w"> </span><span class="nv">reconvert</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">24</span> +<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;days&quot;</span><span class="p">,</span> <span class="s2">&quot;hours&quot;</span><span class="p">]):</span> +<span class="w"> </span><span class="sd">&quot;&quot;&quot;Convert a string to a number of hours, or days&quot;&quot;&quot;</span> + <span class="n">num</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">,</span> <span class="n">value</span><span class="p">)))</span> -<span class="k">return</span><span class="w"> </span><span class="nv">num</span> -</code></pre></div> + <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">&quot;hours&quot;</span><span class="p">:</span> + <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">True</span> -<p><span class="dquo">&#8220;</span>&#8220;&#8220;</p>2023, Semaine 402023-10-08T00:00:00+02:002023-10-08T00:00:00+02:00tag:blog.notmyidea.org,2023-10-08:/2023-semaine-40.html + <span class="k">if</span> <span class="s2">&quot;h&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">&quot;days&quot;</span><span class="p">:</span> + <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid duration value&quot;</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> + <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">False</span> + <span class="k">elif</span> <span class="s2">&quot;d&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> + <span class="k">elif</span> <span class="s2">&quot;w&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">7</span> + <span class="k">elif</span> <span class="s2">&quot;m&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">30</span> + <span class="k">elif</span> <span class="s2">&quot;y&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">365</span> + <span class="k">else</span><span class="p">:</span> + <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid duration value&quot;</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> + + <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">&quot;hours&quot;</span> <span class="ow">and</span> <span class="n">reconvert</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">24</span> + + <span class="k">return</span> <span class="n">num</span> +</code></pre></div>2023, Semaine 402023-10-08T00:00:00+02:002023-10-08T00:00:00+02:00tag:blog.notmyidea.org,2023-10-08:/2023-semaine-40.html <p>Je me suis réservé les matins pour travailler, et je suis content du rythme que ça à donné à ma semaine. C&#8217;était aussi le retour des pomodoros&nbsp;!</p> <h2 id="ce-qui-sest-passe">Ce qui s&#8217;est&nbsp;passé</h2> <dl> diff --git a/feeds/code.atom.xml b/feeds/code.atom.xml index 70015f3..637306b 100644 --- a/feeds/code.atom.xml +++ b/feeds/code.atom.xml @@ -7,9 +7,10 @@ </code></pre></div> <p>The code&nbsp;:</p> -<p><span class="dquo">&#8220;</span>`python -from typing import&nbsp;Literal</p> -<p>def string_to_duration …</p><p>I found myself wanting to convert a string to a duration (int), for some&nbsp;configuration.</p> +<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span> + + +<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value …</span></code></pre></div><p>I found myself wanting to convert a string to a duration (int), for some&nbsp;configuration.</p> <p>Something you can call like&nbsp;this:</p> <div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">&quot;1d&quot;</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">&quot;days&quot;</span><span class="p">)</span> <span class="c1"># returns 1</span> <span class="n">string_to_duration</span><span class="p">(</span><span class="s2">&quot;1d&quot;</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">&quot;hours&quot;</span><span class="p">)</span> <span class="c1"># returns 24</span> @@ -17,37 +18,37 @@ from typing import&nbsp;Literal</p> </code></pre></div> <p>The code&nbsp;:</p> -<p><span class="dquo">&#8220;</span>`python -from typing import&nbsp;Literal</p> -<p>def string_to_duration(value: str, target: Literal[&#8220;days&#8221;, &#8220;hours&#8221;]): - &#8220;&#8221;&#8220;Convert a string to a number of hours, or days&#8221;&#8220;&#8221; - num = int(&#8220;&#8221;.join(filter(str.isdigit,&nbsp;value)))</p> -<div class="highlight"><pre><span></span><code><span class="k">if</span><span class="w"> </span><span class="nv">target</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">&quot;hours&quot;</span>: -<span class="w"> </span><span class="nv">reconvert</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">True</span> +<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span> -<span class="k">if</span><span class="w"> </span><span class="s2">&quot;h&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="nv">target</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">&quot;days&quot;</span>: -<span class="w"> </span><span class="nv">raise</span><span class="w"> </span><span class="nv">ValueError</span><span class="ss">(</span><span class="s2">&quot;Invalid duration value&quot;</span>,<span class="w"> </span><span class="nv">value</span><span class="ss">)</span> -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span> -<span class="w"> </span><span class="nv">reconvert</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">False</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;d&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;w&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">7</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;m&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">30</span> -<span class="nv">elif</span><span class="w"> </span><span class="s2">&quot;y&quot;</span><span class="w"> </span><span class="nv">in</span><span class="w"> </span><span class="nv">value</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">365</span> -<span class="k">else</span>: -<span class="w"> </span><span class="nv">raise</span><span class="w"> </span><span class="nv">ValueError</span><span class="ss">(</span><span class="s2">&quot;Invalid duration value&quot;</span>,<span class="w"> </span><span class="nv">value</span><span class="ss">)</span> -<span class="k">if</span><span class="w"> </span><span class="nv">target</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">&quot;hours&quot;</span><span class="w"> </span><span class="nv">and</span><span class="w"> </span><span class="nv">reconvert</span>: -<span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">num</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">24</span> +<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;days&quot;</span><span class="p">,</span> <span class="s2">&quot;hours&quot;</span><span class="p">]):</span> +<span class="w"> </span><span class="sd">&quot;&quot;&quot;Convert a string to a number of hours, or days&quot;&quot;&quot;</span> + <span class="n">num</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">,</span> <span class="n">value</span><span class="p">)))</span> -<span class="k">return</span><span class="w"> </span><span class="nv">num</span> -</code></pre></div> + <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">&quot;hours&quot;</span><span class="p">:</span> + <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">True</span> -<p><span class="dquo">&#8220;</span>&#8220;&#8220;</p>llm command-line tips2023-09-27T00:00:00+02:002023-09-27T00:00:00+02:00tag:blog.notmyidea.org,2023-09-27:/llm-command-line-tips.html<p>I&#8217;m using <a href="https://llm.datasette.io">llm</a> more and more, and today I had to find back prompts I used in the past. Here is a command I&#8217;ve been using, which allows me to filter the results based on what I want. It leverages <a href="https://sqlutils.datasette.io">sql-utils</a>, a cli tool which is able to …</p><p>I&#8217;m using <a href="https://llm.datasette.io">llm</a> more and more, and today I had to find back prompts I used in the past. Here is a command I&#8217;ve been using, which allows me to filter the results based on what I want. It leverages <a href="https://sqlutils.datasette.io">sql-utils</a>, a cli tool which is able to talk to a <span class="caps">SQLITE</span> database and answer in json, and <a href="https://github.com/jqlang/jq">jq</a> a command-line tool capable of doing requests for&nbsp;json.</p> + <span class="k">if</span> <span class="s2">&quot;h&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">&quot;days&quot;</span><span class="p">:</span> + <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid duration value&quot;</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> + <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">False</span> + <span class="k">elif</span> <span class="s2">&quot;d&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> + <span class="k">elif</span> <span class="s2">&quot;w&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">7</span> + <span class="k">elif</span> <span class="s2">&quot;m&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">30</span> + <span class="k">elif</span> <span class="s2">&quot;y&quot;</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">365</span> + <span class="k">else</span><span class="p">:</span> + <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid duration value&quot;</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> + + <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">&quot;hours&quot;</span> <span class="ow">and</span> <span class="n">reconvert</span><span class="p">:</span> + <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">24</span> + + <span class="k">return</span> <span class="n">num</span> +</code></pre></div>llm command-line tips2023-09-27T00:00:00+02:002023-09-27T00:00:00+02:00tag:blog.notmyidea.org,2023-09-27:/llm-command-line-tips.html<p>I&#8217;m using <a href="https://llm.datasette.io">llm</a> more and more, and today I had to find back prompts I used in the past. Here is a command I&#8217;ve been using, which allows me to filter the results based on what I want. It leverages <a href="https://sqlutils.datasette.io">sql-utils</a>, a cli tool which is able to …</p><p>I&#8217;m using <a href="https://llm.datasette.io">llm</a> more and more, and today I had to find back prompts I used in the past. Here is a command I&#8217;ve been using, which allows me to filter the results based on what I want. It leverages <a href="https://sqlutils.datasette.io">sql-utils</a>, a cli tool which is able to talk to a <span class="caps">SQLITE</span> database and answer in json, and <a href="https://github.com/jqlang/jq">jq</a> a command-line tool capable of doing requests for&nbsp;json.</p> <p>All in all, it&#8217;s pretty satisfying to use. I finally got a simple way to query databases! I&#8217;m also using <a href="https://github.com/charmbracelet/glow">glow</a>, which is capable of transforming markdown into a better version on the&nbsp;terminal.</p> <div class="highlight"><pre><span></span><code>sqlite-utils<span class="w"> </span><span class="s2">&quot;</span><span class="k">$(</span>llm<span class="w"> </span>logs<span class="w"> </span>path<span class="k">)</span><span class="s2">&quot;</span><span class="w"> </span><span class="s2">&quot;SELECT * FROM responses WHERE prompt LIKE &#39;%search%&#39;&quot;</span><span class="w"> </span><span class="p">|</span><span class="w"> </span>jq<span class="w"> </span><span class="s1">&#39;.[].response&#39;</span><span class="w"> </span>-r<span class="w"> </span><span class="p">|</span><span class="w"> </span>glow </code></pre></div> diff --git a/tag/conversion.html b/tag/conversion.html index bd1fc3e..a52c0d6 100644 --- a/tag/conversion.html +++ b/tag/conversion.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …
diff --git a/tag/python.html b/tag/python.html index 6432a38..d1f2480 100644 --- a/tag/python.html +++ b/tag/python.html @@ -37,9 +37,10 @@

The code :

-

`python -from typing import Literal

-

def string_to_duration …

+
from typing import Literal
+
+
+def string_to_duration(value …