smartsheet-tools 0.0.6__tar.gz → 0.0.8__tar.gz
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.
- {smartsheet_tools-0.0.6/smartsheet_tools.egg-info → smartsheet_tools-0.0.8}/PKG-INFO +1 -1
- {smartsheet_tools-0.0.6 → smartsheet_tools-0.0.8}/pyproject.toml +1 -1
- {smartsheet_tools-0.0.6 → smartsheet_tools-0.0.8}/setup.py +1 -1
- {smartsheet_tools-0.0.6 → smartsheet_tools-0.0.8}/smartsheet_tools/__init__.py +39 -9
- {smartsheet_tools-0.0.6 → smartsheet_tools-0.0.8/smartsheet_tools.egg-info}/PKG-INFO +1 -1
- {smartsheet_tools-0.0.6 → smartsheet_tools-0.0.8}/LICENSE +0 -0
- {smartsheet_tools-0.0.6 → smartsheet_tools-0.0.8}/README.md +0 -0
- {smartsheet_tools-0.0.6 → smartsheet_tools-0.0.8}/setup.cfg +0 -0
- {smartsheet_tools-0.0.6 → smartsheet_tools-0.0.8}/smartsheet_tools.egg-info/SOURCES.txt +0 -0
- {smartsheet_tools-0.0.6 → smartsheet_tools-0.0.8}/smartsheet_tools.egg-info/dependency_links.txt +0 -0
- {smartsheet_tools-0.0.6 → smartsheet_tools-0.0.8}/smartsheet_tools.egg-info/requires.txt +0 -0
- {smartsheet_tools-0.0.6 → smartsheet_tools-0.0.8}/smartsheet_tools.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: smartsheet_tools
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.8
|
|
4
4
|
Summary: A collection of convenience functions to aid with transitioning from simple-smartsheet to the SDK API and common tasks
|
|
5
5
|
Author: Ashton Pooley
|
|
6
6
|
Author-email: Ashton Pooley <ashton@ashi.digital>
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "smartsheet_tools" # from setup.py
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.8" # from setup.py
|
|
8
8
|
description = "A collection of convenience functions to aid with transitioning from simple-smartsheet to the SDK API and common tasks"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9" # matches classifiers (3.9–3.12)
|
|
@@ -2,7 +2,7 @@ from setuptools import setup
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name="smartsheet_tools",
|
|
5
|
-
version="0.0.
|
|
5
|
+
version="0.0.8",
|
|
6
6
|
description="A collection of convenience functions to aid with transitioning from simple-smartsheet to the SDK API and common tasks",
|
|
7
7
|
author="Ashton Pooley",
|
|
8
8
|
author_email="Ashton@ashi.digital",
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
+
import time
|
|
2
3
|
import re
|
|
3
|
-
|
|
4
|
+
import warnings
|
|
5
|
+
from smartsheet.models import Cell, Row, Folder, Sheet, Error
|
|
4
6
|
from smartsheet.models import Column
|
|
5
7
|
|
|
6
8
|
# Cache for column types to minimize API calls when correcting date formats
|
|
@@ -61,7 +63,11 @@ def get_cached_column_type(column_id, sheet_obj, prefill=False):
|
|
|
61
63
|
|
|
62
64
|
if column_id not in _COLUMN_TYPE_CACHE[sheet_obj.id]:
|
|
63
65
|
if not prefill:
|
|
64
|
-
|
|
66
|
+
|
|
67
|
+
# Value is not in there and no prefill, so look it up
|
|
68
|
+
for col in sheet_obj.columns:
|
|
69
|
+
_COLUMN_TYPE_CACHE[sheet_obj.id][column_id] = col.type
|
|
70
|
+
|
|
65
71
|
else:
|
|
66
72
|
_COLUMN_TYPE_CACHE[sheet_obj.id][column_id] = prefill
|
|
67
73
|
|
|
@@ -70,6 +76,9 @@ def get_cached_column_type(column_id, sheet_obj, prefill=False):
|
|
|
70
76
|
def get_col_names_of_date_cols(sheet_obj):
|
|
71
77
|
return [c.title for c in sheet_obj.columns if get_cached_column_type(c.id, sheet_obj, prefill=c.type) in ("DATE", "DATETIME")]
|
|
72
78
|
|
|
79
|
+
def get_col_names_of_bool_cols(sheet_obj):
|
|
80
|
+
return [c.title for c in sheet_obj.columns if get_cached_column_type(c.id, sheet_obj, prefill=c.type) == "CHECKBOX"]
|
|
81
|
+
|
|
73
82
|
def brute_force_date_string(s, nonetype_if_fail=False):
|
|
74
83
|
# attempt to parse a date string in common formats to ISO 8601
|
|
75
84
|
if isinstance(s, datetime):
|
|
@@ -91,16 +100,16 @@ def is_date_col(column_id, sheet_obj):
|
|
|
91
100
|
column_type = get_cached_column_type(column_id, sheet_obj)
|
|
92
101
|
return column_type in ("DATE", "DATETIME")
|
|
93
102
|
|
|
94
|
-
def correct_date_format(
|
|
95
|
-
if isinstance(
|
|
96
|
-
|
|
103
|
+
def correct_date_format(value, column_id, sheet_obj, nonetype_if_fail=False):
|
|
104
|
+
if isinstance(value, datetime):
|
|
105
|
+
value = datetime_to_isoformat(value)
|
|
97
106
|
|
|
98
107
|
column_type = get_cached_column_type(column_id, sheet_obj)
|
|
99
108
|
if column_type == "DATE":
|
|
100
|
-
return
|
|
109
|
+
return value.split("T",1)[0]
|
|
101
110
|
elif column_type == "DATETIME":
|
|
102
|
-
return
|
|
103
|
-
return None
|
|
111
|
+
return value
|
|
112
|
+
return None if nonetype_if_fail else value
|
|
104
113
|
|
|
105
114
|
def new_cell(column_id=None, value=None, strict=False, formula=None):
|
|
106
115
|
new_cell = Cell()
|
|
@@ -156,6 +165,27 @@ def walk_workspace_for_folders(smartsheet_client, workspace_id):
|
|
|
156
165
|
def walk_sheet_names_from_workspace(smartsheet_client, workspace_id):
|
|
157
166
|
for sheet in walk_workspace_for_sheets(smartsheet_client, workspace_id):
|
|
158
167
|
yield sheet.name
|
|
168
|
+
|
|
169
|
+
def safe_grab_sheet_by_name(name, smartsheet_client, max_tries=5, delay_seconds=15):
|
|
170
|
+
last_error = None
|
|
171
|
+
for attempt in range(1, max_tries + 1):
|
|
172
|
+
try:
|
|
173
|
+
result = smartsheet_client.Sheets.get_sheet_by_name(name)
|
|
174
|
+
except Exception as exc:
|
|
175
|
+
last_error = exc
|
|
176
|
+
result = None
|
|
177
|
+
|
|
178
|
+
if isinstance(result, Sheet):
|
|
179
|
+
return result
|
|
180
|
+
|
|
181
|
+
if isinstance(result, Error):
|
|
182
|
+
last_error = result
|
|
183
|
+
|
|
184
|
+
if attempt < max_tries:
|
|
185
|
+
warnings.warn(f"failed to grab sheet {name} trying again in {delay_seconds}s")
|
|
186
|
+
time.sleep(delay_seconds)
|
|
187
|
+
|
|
188
|
+
raise RuntimeError(f"failed to grab sheet {name} after {max_tries} tries") from (last_error if isinstance(last_error, Exception) else None)
|
|
159
189
|
|
|
160
190
|
def new_column(column_type, title, index=None, id=None, options=None, symbol=None, primary=False, hidden=False, locked=False):
|
|
161
191
|
new_column = Column()
|
|
@@ -176,4 +206,4 @@ def new_column(column_type, title, index=None, id=None, options=None, symbol=Non
|
|
|
176
206
|
new_column.hidden = True
|
|
177
207
|
if locked:
|
|
178
208
|
new_column.locked = True
|
|
179
|
-
return new_column
|
|
209
|
+
return new_column
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: smartsheet_tools
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.8
|
|
4
4
|
Summary: A collection of convenience functions to aid with transitioning from simple-smartsheet to the SDK API and common tasks
|
|
5
5
|
Author: Ashton Pooley
|
|
6
6
|
Author-email: Ashton Pooley <ashton@ashi.digital>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{smartsheet_tools-0.0.6 → smartsheet_tools-0.0.8}/smartsheet_tools.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|