toolsos 0.2.3__py3-none-any.whl → 0.2.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- toolsos/database/database_connection.py +59 -0
- toolsos/huisstijl/graphs/bargraph.py +11 -1
- toolsos/huisstijl/graphs/graph_styles.py +3 -1
- toolsos/huisstijl/graphs/linegraph.py +2 -1
- toolsos/huisstijl/graphs/piegraph.py +2 -0
- toolsos/huisstijl/graphs/styler.py +21 -14
- toolsos/huisstijl/tables/tables.py +17 -5
- {toolsos-0.2.3.dist-info → toolsos-0.2.4.dist-info}/METADATA +1 -1
- {toolsos-0.2.3.dist-info → toolsos-0.2.4.dist-info}/RECORD +11 -11
- {toolsos-0.2.3.dist-info → toolsos-0.2.4.dist-info}/WHEEL +0 -0
- {toolsos-0.2.3.dist-info → toolsos-0.2.4.dist-info}/top_level.txt +0 -0
|
@@ -2,8 +2,10 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import getpass
|
|
4
4
|
import json
|
|
5
|
+
import os
|
|
5
6
|
import subprocess
|
|
6
7
|
from json import JSONDecodeError
|
|
8
|
+
from pathlib import Path
|
|
7
9
|
from typing import Optional
|
|
8
10
|
|
|
9
11
|
import keyring
|
|
@@ -99,6 +101,63 @@ def get_azure_access_token():
|
|
|
99
101
|
subprocess.run("az login", shell=True)
|
|
100
102
|
|
|
101
103
|
|
|
104
|
+
def get_token_from_pgpass() -> None:
|
|
105
|
+
p = Path(os.getenv("APPDATA")) / "postgresql" / "pgpass.conf"
|
|
106
|
+
with open(p) as f:
|
|
107
|
+
token = f.readline().split(":")[4]
|
|
108
|
+
|
|
109
|
+
return token
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def write_pgpass(
|
|
113
|
+
host: str, port: str, database: str, user: str, path: str | None = None
|
|
114
|
+
) -> None:
|
|
115
|
+
password = get_azure_access_token()
|
|
116
|
+
conn_string = f"{host}:{port}:{database}:{user}:{password}"
|
|
117
|
+
|
|
118
|
+
if not path:
|
|
119
|
+
if os.name == "nt":
|
|
120
|
+
path = Path(os.getenv("APPDATA")) / "postgresql" / "pgpass.conf"
|
|
121
|
+
else:
|
|
122
|
+
path = Path("$home/.pgpass")
|
|
123
|
+
|
|
124
|
+
if not path.parent.exists():
|
|
125
|
+
path.parent.mkdir()
|
|
126
|
+
|
|
127
|
+
with open(path, "w") as f:
|
|
128
|
+
f.write(conn_string)
|
|
129
|
+
|
|
130
|
+
if os.name != "nt":
|
|
131
|
+
path.chmod("0600")
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def write_multiple_pgpass(conn_details, path: str | None = None):
|
|
135
|
+
password = get_azure_access_token()
|
|
136
|
+
|
|
137
|
+
conn_strings = []
|
|
138
|
+
for c in conn_details:
|
|
139
|
+
c_string = f'{c["host"]}:{c["port"]}:{c["database"]}:{c["user"]}:{password}'
|
|
140
|
+
conn_strings.append(c_string)
|
|
141
|
+
|
|
142
|
+
if not path:
|
|
143
|
+
if os.name == "nt":
|
|
144
|
+
path = Path(os.getenv("APPDATA")) / "postgresql" / "pgpass.conf"
|
|
145
|
+
else:
|
|
146
|
+
path = Path("$home/.pgpass")
|
|
147
|
+
|
|
148
|
+
if not path.parent.exists():
|
|
149
|
+
path.parent.mkdir()
|
|
150
|
+
|
|
151
|
+
with open(path, "w") as f:
|
|
152
|
+
f.writelines(line + "\n" for line in conn_strings)
|
|
153
|
+
|
|
154
|
+
if os.name != "nt":
|
|
155
|
+
path.chmod("0600")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# Writing connection settings to pgpass.conf
|
|
159
|
+
|
|
160
|
+
|
|
102
161
|
if __name__ == "__main__":
|
|
103
162
|
...
|
|
104
163
|
# Examples
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import plotly.express as px
|
|
2
|
+
|
|
2
3
|
from .styler import BaseStyle
|
|
3
4
|
|
|
4
5
|
basestyle = BaseStyle()
|
|
@@ -14,6 +15,7 @@ def bar(
|
|
|
14
15
|
barmode=None,
|
|
15
16
|
width=750,
|
|
16
17
|
height=490,
|
|
18
|
+
font="Amsterdam Sans",
|
|
17
19
|
**kwargs,
|
|
18
20
|
):
|
|
19
21
|
fig = px.bar(
|
|
@@ -21,7 +23,7 @@ def bar(
|
|
|
21
23
|
x=x,
|
|
22
24
|
y=y,
|
|
23
25
|
color=color,
|
|
24
|
-
template=basestyle.get_base_template("bar", orientation=orientation),
|
|
26
|
+
template=basestyle.get_base_template("bar", orientation=orientation, font=font),
|
|
25
27
|
width=width,
|
|
26
28
|
color_discrete_sequence=color_discrete_sequence,
|
|
27
29
|
height=height,
|
|
@@ -43,6 +45,7 @@ def stacked_single(
|
|
|
43
45
|
color: str = None,
|
|
44
46
|
color_discrete_sequence: list = None,
|
|
45
47
|
orientation="v",
|
|
48
|
+
font="Amsterdam Sans",
|
|
46
49
|
**kwargs,
|
|
47
50
|
):
|
|
48
51
|
fig = bar(
|
|
@@ -53,6 +56,7 @@ def stacked_single(
|
|
|
53
56
|
color_discrete_sequence=color_discrete_sequence,
|
|
54
57
|
barmode="relative",
|
|
55
58
|
orientation=orientation,
|
|
59
|
+
font=font,
|
|
56
60
|
**kwargs,
|
|
57
61
|
)
|
|
58
62
|
|
|
@@ -71,6 +75,7 @@ def stacked_multiple(
|
|
|
71
75
|
color: str = None,
|
|
72
76
|
color_discrete_sequence: list = None,
|
|
73
77
|
orientation="v",
|
|
78
|
+
font="Amsterdam Sans",
|
|
74
79
|
**kwargs,
|
|
75
80
|
):
|
|
76
81
|
fig = bar(
|
|
@@ -81,6 +86,7 @@ def stacked_multiple(
|
|
|
81
86
|
color_discrete_sequence=color_discrete_sequence,
|
|
82
87
|
barmode="stack",
|
|
83
88
|
orientation=orientation,
|
|
89
|
+
font=font,
|
|
84
90
|
**kwargs,
|
|
85
91
|
)
|
|
86
92
|
|
|
@@ -94,6 +100,7 @@ def grouped(
|
|
|
94
100
|
color: str = None,
|
|
95
101
|
color_discrete_sequence: list = None,
|
|
96
102
|
orientation="v",
|
|
103
|
+
font="Amsterdam Sans",
|
|
97
104
|
**kwargs,
|
|
98
105
|
):
|
|
99
106
|
fig = bar(
|
|
@@ -104,6 +111,7 @@ def grouped(
|
|
|
104
111
|
color_discrete_sequence=color_discrete_sequence,
|
|
105
112
|
barmode="group",
|
|
106
113
|
orientation=orientation,
|
|
114
|
+
font=font,
|
|
107
115
|
**kwargs,
|
|
108
116
|
)
|
|
109
117
|
|
|
@@ -116,6 +124,7 @@ def single(
|
|
|
116
124
|
y: str,
|
|
117
125
|
color_discrete_sequence: list = None,
|
|
118
126
|
orientation="v",
|
|
127
|
+
font="Amsterdam Sans",
|
|
119
128
|
**kwargs,
|
|
120
129
|
):
|
|
121
130
|
fig = bar(
|
|
@@ -124,6 +133,7 @@ def single(
|
|
|
124
133
|
y=y,
|
|
125
134
|
color_discrete_sequence=color_discrete_sequence,
|
|
126
135
|
orientation=orientation,
|
|
136
|
+
font=font,
|
|
127
137
|
**kwargs,
|
|
128
138
|
)
|
|
129
139
|
|
|
@@ -16,8 +16,10 @@ STYLE_OLD = {
|
|
|
16
16
|
|
|
17
17
|
STYLE_NEW = {
|
|
18
18
|
"font_bold": {"family": "Amsterdam Sans ExtraBold, Corbel", "size": 15},
|
|
19
|
+
"font_bold_corbel": {"family": "Corbel Bold", "size": 15},
|
|
19
20
|
"font": {"family": "Amsterdam Sans, Corbel", "size": 15},
|
|
20
|
-
"
|
|
21
|
+
"font_corbel": {"family": "Corbel", "size": 15},
|
|
22
|
+
"axis_font": {"family": "Amsterdam Sans ExtraBold, Corbel", "size": 15},
|
|
21
23
|
"plot_bgcolor": "#FFFFFF",
|
|
22
24
|
"gridline_color": "#dbdbdb",
|
|
23
25
|
"gridline_width": 0.75,
|
|
@@ -13,6 +13,7 @@ def line(
|
|
|
13
13
|
width=750,
|
|
14
14
|
height=490,
|
|
15
15
|
color_discrete_sequence=None,
|
|
16
|
+
font="Amsterdam Sans",
|
|
16
17
|
**kwargs,
|
|
17
18
|
):
|
|
18
19
|
fig = px.line(
|
|
@@ -23,7 +24,7 @@ def line(
|
|
|
23
24
|
width=width,
|
|
24
25
|
height=height,
|
|
25
26
|
color_discrete_sequence=color_discrete_sequence,
|
|
26
|
-
template=BaseStyle().get_base_template(graph_type="line"),
|
|
27
|
+
template=BaseStyle().get_base_template(graph_type="line", font=font),
|
|
27
28
|
**kwargs,
|
|
28
29
|
)
|
|
29
30
|
|
|
@@ -14,6 +14,7 @@ def pie(
|
|
|
14
14
|
height=490,
|
|
15
15
|
text_format: str = None,
|
|
16
16
|
color_discrete_sequence=None,
|
|
17
|
+
font="Amsterdam Sans",
|
|
17
18
|
**kwargs,
|
|
18
19
|
):
|
|
19
20
|
fig = px.pie(
|
|
@@ -25,6 +26,7 @@ def pie(
|
|
|
25
26
|
hole=hole,
|
|
26
27
|
template=BaseStyle().get_base_template(),
|
|
27
28
|
color_discrete_sequence=color_discrete_sequence,
|
|
29
|
+
font=font,
|
|
28
30
|
**kwargs,
|
|
29
31
|
)
|
|
30
32
|
|
|
@@ -109,7 +109,6 @@ class BaseStyle:
|
|
|
109
109
|
self.style = json.load(file)
|
|
110
110
|
|
|
111
111
|
def _get_axis_format(self):
|
|
112
|
-
self.gridline_color = "#dbdbdb" # Jorren vragen om deze aan te passen
|
|
113
112
|
|
|
114
113
|
return {
|
|
115
114
|
"zerolinecolor": self.style["gridline_color"],
|
|
@@ -121,29 +120,37 @@ class BaseStyle:
|
|
|
121
120
|
"showgrid": self.style["showgrid"],
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
def _get_base_template_layout(self):
|
|
123
|
+
def _get_base_template_layout(self, font):
|
|
124
|
+
if font == "Amsterdam Sans":
|
|
125
|
+
font_ = self.style["font"]
|
|
126
|
+
font_bold_ = self.style["font_bold"]
|
|
127
|
+
elif font == "Corbel":
|
|
128
|
+
font_ = self.style["font_corbel"]
|
|
129
|
+
font_bold_ = self.style["font_bold_corbel"]
|
|
130
|
+
else:
|
|
131
|
+
raise ValueError("Font should be 'Amsterdam Sans' or 'Corbel'")
|
|
132
|
+
|
|
125
133
|
return go.layout.Template(
|
|
126
134
|
layout={
|
|
127
|
-
# "font": self.styles["font_bold"],
|
|
128
135
|
"xaxis": {
|
|
129
|
-
"tickfont":
|
|
136
|
+
"tickfont": font_bold_,
|
|
130
137
|
},
|
|
131
138
|
"yaxis": {
|
|
132
|
-
"tickfont":
|
|
133
|
-
"family": self.style["axis_font"]["family"],
|
|
134
|
-
"size": self.style["axis_font"]["size"],
|
|
135
|
-
},
|
|
139
|
+
"tickfont": font_bold_,
|
|
136
140
|
},
|
|
137
|
-
"legend": {"font":
|
|
141
|
+
"legend": {"font": font_},
|
|
138
142
|
"plot_bgcolor": self.style["plot_bgcolor"],
|
|
139
|
-
|
|
140
|
-
"
|
|
141
|
-
"font": self.style["font_bold"],
|
|
143
|
+
"separators": ",",
|
|
144
|
+
"font": font_bold_,
|
|
142
145
|
}
|
|
143
146
|
)
|
|
144
147
|
|
|
145
148
|
def get_base_template(
|
|
146
|
-
self,
|
|
149
|
+
self,
|
|
150
|
+
graph_type: str = None,
|
|
151
|
+
orientation: str = None,
|
|
152
|
+
colors: str = None,
|
|
153
|
+
font: str = "Amsterdam Sans",
|
|
147
154
|
):
|
|
148
155
|
"""[summary]
|
|
149
156
|
|
|
@@ -158,7 +165,7 @@ class BaseStyle:
|
|
|
158
165
|
Returns:
|
|
159
166
|
[type]: [description]
|
|
160
167
|
"""
|
|
161
|
-
base_template = self._get_base_template_layout()
|
|
168
|
+
base_template = self._get_base_template_layout(font)
|
|
162
169
|
axis_format = self._get_axis_format()
|
|
163
170
|
|
|
164
171
|
if graph_type == "bar":
|
|
@@ -379,6 +379,7 @@ def write_to_worksheet(
|
|
|
379
379
|
source: str | None = None,
|
|
380
380
|
col_filter: bool | None = None,
|
|
381
381
|
col_widths: list | None = None,
|
|
382
|
+
min_column_width: int | None = None,
|
|
382
383
|
cells_to_merge: list[list[int]] | None = None,
|
|
383
384
|
) -> None:
|
|
384
385
|
"""Writing data to worksheet. Used for writing values to cells and formatting the cells
|
|
@@ -423,7 +424,7 @@ def write_to_worksheet(
|
|
|
423
424
|
_insert_source(ws, source, arr)
|
|
424
425
|
|
|
425
426
|
if col_widths:
|
|
426
|
-
_set_column_widths(ws, col_widths)
|
|
427
|
+
_set_column_widths(ws, col_widths, min_column_width)
|
|
427
428
|
|
|
428
429
|
if title:
|
|
429
430
|
_insert_title(ws, title)
|
|
@@ -432,9 +433,16 @@ def write_to_worksheet(
|
|
|
432
433
|
_merge_cells(ws, cells_to_merge, title)
|
|
433
434
|
|
|
434
435
|
|
|
435
|
-
def _set_column_widths(
|
|
436
|
+
def _set_column_widths(
|
|
437
|
+
ws: Any, col_widths: list[int], min_column_width: int | None
|
|
438
|
+
) -> None:
|
|
436
439
|
for idx, col_width in enumerate(col_widths):
|
|
437
440
|
col_letter = get_column_letter(idx + 1)
|
|
441
|
+
|
|
442
|
+
if min_column_width:
|
|
443
|
+
if col_width < min_column_width:
|
|
444
|
+
col_width = min_column_width
|
|
445
|
+
|
|
438
446
|
ws.column_dimensions[col_letter].width = col_width
|
|
439
447
|
|
|
440
448
|
|
|
@@ -493,6 +501,7 @@ def write_table(
|
|
|
493
501
|
blue_border_row_ids: int | list[int] | None = None,
|
|
494
502
|
number_format: str = "0.0",
|
|
495
503
|
autofit_columns: str | None = "column_names",
|
|
504
|
+
min_column_width: int | None = None,
|
|
496
505
|
col_filter: bool | None = False,
|
|
497
506
|
style: str = "old",
|
|
498
507
|
combine_multiindex: bool | int = False,
|
|
@@ -508,9 +517,6 @@ def write_table(
|
|
|
508
517
|
data = {"Sheet1": data}
|
|
509
518
|
|
|
510
519
|
for sheet_name, df in data.items():
|
|
511
|
-
if column_names_to_string == True:
|
|
512
|
-
df = cols_to_str(df)
|
|
513
|
-
|
|
514
520
|
format_worksheet(
|
|
515
521
|
wb=wb,
|
|
516
522
|
df=df,
|
|
@@ -534,6 +540,7 @@ def write_table(
|
|
|
534
540
|
blue_border_row_ids=blue_border_row_ids,
|
|
535
541
|
number_format=number_format,
|
|
536
542
|
autofit_columns=autofit_columns,
|
|
543
|
+
min_column_width=min_column_width,
|
|
537
544
|
col_filter=col_filter,
|
|
538
545
|
combine_multiindex=combine_multiindex,
|
|
539
546
|
column_names_to_string=column_names_to_string,
|
|
@@ -582,6 +589,7 @@ def format_worksheet(
|
|
|
582
589
|
blue_border_row_ids: int | list[int] | None = None,
|
|
583
590
|
number_format: str = "0.0",
|
|
584
591
|
autofit_columns: str | None = "column_names",
|
|
592
|
+
min_column_width: int | None = None,
|
|
585
593
|
col_filter: bool | None = False,
|
|
586
594
|
combine_multiindex: bool | int = False,
|
|
587
595
|
column_names_to_string: bool = True,
|
|
@@ -607,6 +615,9 @@ def format_worksheet(
|
|
|
607
615
|
perc_col_format (str, optional): The formatting string of percentage columns. Defaults to None.
|
|
608
616
|
col_filter (bool, optional): Set filter on columns. Defaults to False.
|
|
609
617
|
"""
|
|
618
|
+
if column_names_to_string == True:
|
|
619
|
+
df = cols_to_str(df)
|
|
620
|
+
|
|
610
621
|
arr = df_to_array(df)
|
|
611
622
|
|
|
612
623
|
blue_rows = []
|
|
@@ -711,4 +722,5 @@ def format_worksheet(
|
|
|
711
722
|
col_filter=col_filter,
|
|
712
723
|
col_widths=col_widths,
|
|
713
724
|
cells_to_merge=cells_to_merge,
|
|
725
|
+
min_column_width=min_column_width,
|
|
714
726
|
)
|
|
@@ -5,21 +5,21 @@ toolsos/download.py,sha256=88hehmPL5m5d1nrcJjltuh4xrCItF5EYHaZdHOcSt-g,2652
|
|
|
5
5
|
toolsos/geo.py,sha256=_OexkeUgXcnPW1mw27VN6fMcX2PMUSljLwIg48Xkv3M,2412
|
|
6
6
|
toolsos/helpers.py,sha256=VeOl-fLgePCbjEmAQdVmYe7z8OE1pISeDDuP1t5QSxM,997
|
|
7
7
|
toolsos/polars_helpers.py,sha256=P3RHLQFeDL7-9U_Q1n4ma_NSkdYAiker4pnc57uluHw,770
|
|
8
|
-
toolsos/database/database_connection.py,sha256=
|
|
8
|
+
toolsos/database/database_connection.py,sha256=NTgwXLJ7LFrTlMr74W9Yge8hLyQG0DCW4t5UuwtoP18,4920
|
|
9
9
|
toolsos/database/database_transfer.py,sha256=1ghq5VEtKyOdCKdM45uOyrZSoXMuWsdC35R3WNuFvdU,1827
|
|
10
10
|
toolsos/huisstijl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
11
|
toolsos/huisstijl/colors.py,sha256=lSCHCdSjge5cGfLfAObd6mV6TaXq3QGImLOmoGJpGkw,1484
|
|
12
12
|
toolsos/huisstijl/graphs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
-
toolsos/huisstijl/graphs/bargraph.py,sha256=
|
|
14
|
-
toolsos/huisstijl/graphs/graph_styles.py,sha256=
|
|
15
|
-
toolsos/huisstijl/graphs/linegraph.py,sha256=
|
|
16
|
-
toolsos/huisstijl/graphs/piegraph.py,sha256=
|
|
17
|
-
toolsos/huisstijl/graphs/styler.py,sha256
|
|
13
|
+
toolsos/huisstijl/graphs/bargraph.py,sha256=HYl01_euh23iDYSUhnAzYAXS0DhDpg9eLRjJEpeR6iU,2815
|
|
14
|
+
toolsos/huisstijl/graphs/graph_styles.py,sha256=Z9LLH7j8ODTsYMYK0rslacphuiRDcq5_IpSjEEiK2VY,975
|
|
15
|
+
toolsos/huisstijl/graphs/linegraph.py,sha256=dMUarRe31SXaY78OCXLy-PgnU8LlVJ9KkzKaHhDtuuI,698
|
|
16
|
+
toolsos/huisstijl/graphs/piegraph.py,sha256=tHWQlM5BP03Pq044-pONoyYlDRNyG-hC1itwsoZ7DDA,714
|
|
17
|
+
toolsos/huisstijl/graphs/styler.py,sha256=-uZ7pjY1G39XvmaGHQd31gPRxjxmJGhYZk8xhy2JUWc,6623
|
|
18
18
|
toolsos/huisstijl/tables/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
19
|
toolsos/huisstijl/tables/table_helpers.py,sha256=jsQ6lw93sxtGJGrUn8X2_LyA2vYYnytngpUI5A_wpWQ,2037
|
|
20
20
|
toolsos/huisstijl/tables/table_styles.py,sha256=oYU6GJcfqlKpZof5PUjPsA7woJ3Tew78CHPyT0_jY6w,1343
|
|
21
|
-
toolsos/huisstijl/tables/tables.py,sha256=
|
|
22
|
-
toolsos-0.2.
|
|
23
|
-
toolsos-0.2.
|
|
24
|
-
toolsos-0.2.
|
|
25
|
-
toolsos-0.2.
|
|
21
|
+
toolsos/huisstijl/tables/tables.py,sha256=67vYOe4DAOyZDPCdc4BOEcPJ80IJLCGilHyQNSMrIvo,23967
|
|
22
|
+
toolsos-0.2.4.dist-info/METADATA,sha256=TX31wvxxA7reLc6bKCtkzAuq20DELKfSkDQfvFSJAO8,2433
|
|
23
|
+
toolsos-0.2.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
24
|
+
toolsos-0.2.4.dist-info/top_level.txt,sha256=2ClEjUBbtfDQ8oPwvWRy1Sz2nrkLCXlg0mHaMdCWia0,8
|
|
25
|
+
toolsos-0.2.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|