kisa-utils 0.37.20__py3-none-any.whl → 0.39.0__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.
kisa_utils/dates.py CHANGED
@@ -170,6 +170,20 @@ def dateFrom(date:str, days:int, hours:int=0) -> str:
170
170
  _date = datetime.datetime.strptime(date, '%Y-%m-%d')
171
171
  return str(_date + datetime.timedelta(days=days, hours=hours))[:10]
172
172
 
173
+ def TimeFrom(timestamp:str, days:int=0, hours:int=0, minutes:int=0, seconds:int=0) -> str:
174
+ '''
175
+ get the time thats `days` + `hours` + `minutes` + `seconds` from `timestamp`
176
+ Args:
177
+ timestamp(str): the reference timestamp to use, format is `YYYY-MM-DD HH:MM:SS`
178
+ days(int): days from the reference timestamp
179
+ hours(int): hours to include to the days to ge tthe new date
180
+ minutes(int): minutes to include to the days to ge the new date
181
+ seconds(int): seconds to include to the days to ge the new date
182
+ ```
183
+ '''
184
+ _tstamp = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
185
+ return str(_tstamp + datetime.timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds))
186
+
173
187
  def dateFromNow(days=0,hours=0) -> str:
174
188
  '''
175
189
  get the timestamp(not date) thats `days` + `hours` from the current time
@@ -186,6 +200,20 @@ def dateFromNow(days=0,hours=0) -> str:
186
200
  now = datetime.datetime.utcnow() + datetime.timedelta(hours=3.00)
187
201
  return str(now+datetime.timedelta(days=days, hours=hours))[:19]
188
202
 
203
+ def TimeFromNow(days:int=0, hours:int=0, minutes:int=0, seconds:int=0) -> str:
204
+ '''
205
+ get the time thats `days` + `hours` + `minutes` + `seconds` from `timestamp`
206
+ Args:
207
+ days(int): days from the reference timestamp
208
+ hours(int): hours to include to the days to ge tthe new date
209
+ minutes(int): minutes to include to the days to ge the new date
210
+ seconds(int): seconds to include to the days to ge the new date
211
+ ```
212
+ '''
213
+ timestamp = currentTimestamp()
214
+ return TimeFrom(timestamp, days, hours, minutes, seconds)
215
+
216
+
189
217
  # thanks to airtel & MTN strange date formats, we have this
190
218
  def standardizedDate(date:str, fmt:str=''):
191
219
  '''
kisa_utils/db.py CHANGED
@@ -955,11 +955,10 @@ class Api:
955
955
  reply['log'] = 'database not open'
956
956
  return reply if not self.__returnKISAResponse else Error(reply['log'])
957
957
 
958
- if self.__withContextCount > 1:
958
+ if not self.inTopLevelContext:
959
959
  reply['log'] = 'can not commit transaction in non top-level context'
960
960
  return reply if not self.__returnKISAResponse else Error(reply['log'])
961
961
 
962
-
963
962
  for op in self.__transactionData:
964
963
  if self.__transactionData[op]['failed']:
965
964
  reply['log'] = f'{self.__transactionData[op]["failed"]} `{op}` operation(s) returned a `False` status'
@@ -1103,6 +1102,14 @@ class Api:
1103
1102
  def __bool__(self)->bool:
1104
1103
  return self.isOpen
1105
1104
 
1105
+ @property
1106
+ def inTopLevelContext(self) -> bool:
1107
+ '''
1108
+ check if the opened db-handle is in the top-most `with` context.
1109
+ If it is, then its okay to commit a transaction
1110
+ '''
1111
+ return self.__withContextCount <= 1
1112
+
1106
1113
  Handle = Api
1107
1114
 
1108
1115
  def transaction(*dbArgs, **dbKwargs) -> dict|Response:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kisa-utils
3
- Version: 0.37.20
3
+ Version: 0.39.0
4
4
  Summary: Utility functions and modules for KISA Developers
5
5
  Author: Tom Bukenya
6
6
  Author-email: glayn2bukman@gmail.com
@@ -2,8 +2,8 @@ kisa_utils/__init__.py,sha256=iXjGTol3UxJkh_cyISYEAY_yWC5ZlNvIRXFuuiHx76Q,621
2
2
  kisa_utils/cache.py,sha256=4Ue5G3QhHSQAmIfQKYgWKWjNL4rA4wLLd_RdBLb2ABY,7345
3
3
  kisa_utils/codes.py,sha256=PV_S53Skggf4XetOdYoIKtEmM8cpN5wZwUlxje70WZY,904
4
4
  kisa_utils/config.py,sha256=NfluzGKTh66qfNtC-Ae0zNb1XzMTgU2Me9Vi82R9c1E,2285
5
- kisa_utils/dates.py,sha256=kcNqoY_iguG9hSzABMIBqeL3MGz3n4MRIXuW4OxRHLs,12662
6
- kisa_utils/db.py,sha256=QH9nvwc3Lr-NyUA-47Rae-s2xeMIE6m2rNGozcpr2jg,48950
5
+ kisa_utils/dates.py,sha256=zxe4n0PdKReZjK5ZkvnCZtJ55lk5oqu9oS8VX_nLozw,13966
6
+ kisa_utils/db.py,sha256=tVNMV-hc-oPxR4iRSX-d82Gi4fQwI5Cga1eP8SLvHFs,49202
7
7
  kisa_utils/encryption.py,sha256=nFzNpzWV_D9uSEq4FsgCnlS7FQtqWP9fvM_81rsfcLo,4218
8
8
  kisa_utils/enqueue.py,sha256=VIliaMvw4MUdOqts0dXdZCYNxs-QrOVjIRAR3scGrRM,11786
9
9
  kisa_utils/figures.py,sha256=pYIpQzu1OXRSsY1d98GhgPifnIRmgl-r7S32ai-Ms0c,3731
@@ -23,7 +23,7 @@ kisa_utils/servers/flask.py,sha256=o76cJKlQ3L8EOVdHUF092qwoAZMzgttuLt0mMhtCsGI,4
23
23
  kisa_utils/structures/__init__.py,sha256=JBU1j3A42jQ62ALKnsS1Hav9YXcYwjDw1wQJtohXPbU,83
24
24
  kisa_utils/structures/utils.py,sha256=665rXIapGwFqejizeJwy3DryeskCQOdgP25BCdLkGvk,2898
25
25
  kisa_utils/structures/validator.py,sha256=Y4UmB4TH7N-GkK22EV1WOsPWjTeqxVWLTentl1keZD4,4053
26
- kisa_utils-0.37.20.dist-info/METADATA,sha256=01cNCPOuqmY6hTmZ3KYeOqf3XkVDSi8GyvQRdyigNSY,478
27
- kisa_utils-0.37.20.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
28
- kisa_utils-0.37.20.dist-info/top_level.txt,sha256=URxY4sRuqmirOxWtztpVmPoGQdksEMYO6hmYsEDGz2Y,75
29
- kisa_utils-0.37.20.dist-info/RECORD,,
26
+ kisa_utils-0.39.0.dist-info/METADATA,sha256=M6VVyZ0NOG7urg1fPt48fHuxc85qD0keInyLNBq4LQY,477
27
+ kisa_utils-0.39.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
28
+ kisa_utils-0.39.0.dist-info/top_level.txt,sha256=URxY4sRuqmirOxWtztpVmPoGQdksEMYO6hmYsEDGz2Y,75
29
+ kisa_utils-0.39.0.dist-info/RECORD,,