kisa-utils 0.42.15__py3-none-any.whl → 0.43.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/__init__.py CHANGED
@@ -21,3 +21,5 @@ from kisa_utils import dataStructures
21
21
 
22
22
  from kisa_utils import queues
23
23
  from kisa_utils.queues.callables import enqueueFunctionCalls
24
+
25
+ from kisa_utils import score
kisa_utils/remote.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import requests
2
+ from kisa_utils.dataStructures import KDict
2
3
 
3
- def sendRequest(url:str|bytes, method:str|bytes='post', jsonPayload:dict={}, timeout:int=180, **requestKwargs:dict) -> dict:
4
+ def sendRequest(url:str|bytes, method:str|bytes='post', jsonPayload:dict={}, timeout:int=180, **requestKwargs:dict) -> KDict:
4
5
  '''
5
6
  attempt to send request with JSON payload.
6
7
  Args:
@@ -23,7 +24,7 @@ def sendRequest(url:str|bytes, method:str|bytes='post', jsonPayload:dict={}, tim
23
24
  @return {'status':BOOL, 'log':STR, }
24
25
  '''
25
26
 
26
- reply = {'status':False, 'log':'', 'response':None}
27
+ reply = KDict({'status':False, 'log':'', 'response':None, 'statusCode': None})
27
28
 
28
29
  method = method.lower()
29
30
  if method not in ['get','post']:
@@ -39,6 +40,8 @@ def sendRequest(url:str|bytes, method:str|bytes='post', jsonPayload:dict={}, tim
39
40
  reply['log'] = 'invalid method given'
40
41
  return reply
41
42
 
43
+ reply.statusCode = response.status_code
44
+
42
45
  if response.status_code!=200:
43
46
  try: reply['response'] = response.json()
44
47
  except: pass
@@ -48,11 +51,11 @@ def sendRequest(url:str|bytes, method:str|bytes='post', jsonPayload:dict={}, tim
48
51
 
49
52
  try:
50
53
  responseJSON = response.json()
51
- reply['response'] = responseJSON
54
+ reply['response'] = KDict(responseJSON) if isinstance(responseJSON, dict) else responseJSON
52
55
  reply['status'] = True
53
56
  return reply
54
- except:
55
- reply['log'] = 'no JSON reply got'
57
+ except Exception as e:
58
+ reply['log'] = f'no JSON reply got: {e}'
56
59
  return reply
57
60
 
58
61
  except requests.exceptions.Timeout:
kisa_utils/score.py ADDED
@@ -0,0 +1,55 @@
1
+ import itertools
2
+ import difflib
3
+ from kisa_utils.functionUtils import enforceRequirements
4
+
5
+ def __removeNonAlpha(name:str)->str:
6
+ return ''.join([xter for xter in name if xter.isalpha() or ' '==xter])
7
+
8
+ def __getCommonCase(name:str)->str:
9
+ return name.upper()
10
+
11
+ def __getPermutations(names:list[str], itemsPerResult:int=-1) -> list[str]:
12
+ if -1== itemsPerResult:
13
+ return [''.join(p) for p in itertools.permutations(names)]
14
+
15
+ results = []
16
+ for nameCombination in itertools.combinations(names, itemsPerResult):
17
+ results += [''.join(p) for p in itertools.permutations(nameCombination)]
18
+
19
+ return results
20
+
21
+ @enforceRequirements
22
+ def getNamesMatchScore(namesA:str, namesB:str, /) -> float:
23
+ '''
24
+ Arguments:
25
+ namesA(str): first set of names eg 'John Doe'
26
+ namesB(str): second set of names eg 'Jane Doe'
27
+ Returns:
28
+ score is in range 0.0 - 100.0
29
+ '''
30
+ score:float = 0.0
31
+ if not (namesA and namesB): return score
32
+
33
+ # print(f'original: `{namesA}` <-> `{namesB}`')
34
+ namesA, namesB = __getCommonCase(namesA), __getCommonCase(namesB)
35
+ namesA, namesB = __removeNonAlpha(namesA), __removeNonAlpha(namesB)
36
+
37
+ namesListA, namesListB = [n for n in namesA.split(' ') if n], [n for n in namesB.split(' ') if n]
38
+ namesListA.sort(); namesListB.sort()
39
+
40
+ if not (len(namesListA)>1 and len(namesListB)>1): return score
41
+
42
+ # print(f'cleaned: `{" ".join(namesListA)}` <-> `{" ".join(namesListB)}`')
43
+
44
+ if namesListA == namesListB: return 100.0
45
+
46
+ leastNameCount = min(len(namesListA), len(namesListB))
47
+
48
+ for permutationA in __getPermutations(namesListA, itemsPerResult=leastNameCount):
49
+ for permutationB in __getPermutations(namesListB, itemsPerResult=leastNameCount):
50
+ if (_score := difflib.SequenceMatcher(None, permutationA, permutationB).ratio()*100) > score:
51
+ print(f' {permutationA}, {permutationB}')
52
+ score = _score
53
+ if 100.0 == score: return score
54
+
55
+ return score
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kisa-utils
3
- Version: 0.42.15
3
+ Version: 0.43.0
4
4
  Summary: Utility functions and modules for KISA Developers
5
5
  Author: Tom Bukenya
6
6
  Author-email: glayn2bukman@gmail.com
@@ -1,4 +1,4 @@
1
- kisa_utils/__init__.py,sha256=-g5gBmI4gV840-Brg1V1aZ_R_r3n_csB-PlRRdUV_UQ,745
1
+ kisa_utils/__init__.py,sha256=7zgEMAjPO7gJ98ob-psV7xGciG94jN5BcissMZMh4lk,774
2
2
  kisa_utils/cache.py,sha256=WOL3e0wvoyESXTtlbVnUg9TYUoLzg64sLP9J4b4ti9k,7377
3
3
  kisa_utils/codes.py,sha256=PV_S53Skggf4XetOdYoIKtEmM8cpN5wZwUlxje70WZY,904
4
4
  kisa_utils/config.py,sha256=vfwka6Wuz80su6_GgjuKhxolnzj1enw8cpgQPYm17l8,2357
@@ -9,8 +9,9 @@ kisa_utils/encryption.py,sha256=nFzNpzWV_D9uSEq4FsgCnlS7FQtqWP9fvM_81rsfcLo,4218
9
9
  kisa_utils/figures.py,sha256=pYIpQzu1OXRSsY1d98GhgPifnIRmgl-r7S32ai-Ms0c,3731
10
10
  kisa_utils/functionUtils.py,sha256=PlXjnmU1uJWNdISlJJ3SCgavTsgNBoebaa9dtWSFhRA,6553
11
11
  kisa_utils/log.py,sha256=0TYdxcIBts026RCSuVIQBcZ-CW1ES7n3M1nEIjmeLTM,2295
12
- kisa_utils/remote.py,sha256=e6Ho78Lc1hd1PO_NrDydo4ssP1GQCyBGAImJn-s6rPs,2172
12
+ kisa_utils/remote.py,sha256=z5QTKC0Mb_wMWVHWfUHR1XOOek-A2fNjo1GyFPhAB8s,2373
13
13
  kisa_utils/response.py,sha256=asETUBkeF5OlSTwa-coa7lZDCKmQlHCmHf6eaZFl8CU,4560
14
+ kisa_utils/score.py,sha256=sulT7dvBoE_6upvbfjfWCMoC5Fn4wBhRU3aG5_uNFvE,2003
14
15
  kisa_utils/standardize.py,sha256=nt-uzHQFoKxGscD_MpDYXw65Teg3724whAqa6Kh_zhE,2231
15
16
  kisa_utils/storage.py,sha256=6NdEVrHMS7WB_vmCwiGigIinu-EjxalFJhk1kj-_vWs,5990
16
17
  kisa_utils/threads.py,sha256=PstMHimkOABXlYmKJi5SHcevzm1JuFGNZSlF0bGzuGk,13137
@@ -27,7 +28,7 @@ kisa_utils/servers/flask.py,sha256=XZYY1pWnP1mSvaS5Uv8G3EFJV5BJBQtU2gDbO8suvLc,4
27
28
  kisa_utils/structures/__init__.py,sha256=JBU1j3A42jQ62ALKnsS1Hav9YXcYwjDw1wQJtohXPbU,83
28
29
  kisa_utils/structures/utils.py,sha256=665rXIapGwFqejizeJwy3DryeskCQOdgP25BCdLkGvk,2898
29
30
  kisa_utils/structures/validator.py,sha256=oCSgY_itst6bZdC5g8yVU4-lSH2xnUsOx3X-oPyV7nA,4626
30
- kisa_utils-0.42.15.dist-info/METADATA,sha256=YWPQ2Fm5D9WgRSfjb6o98jEQUC67jO7bMYCYh3txk14,478
31
- kisa_utils-0.42.15.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
32
- kisa_utils-0.42.15.dist-info/top_level.txt,sha256=GFOLXZYqpBG9xtscGa2uGJAEiZ5NwsqHBH9NylnB29M,11
33
- kisa_utils-0.42.15.dist-info/RECORD,,
31
+ kisa_utils-0.43.0.dist-info/METADATA,sha256=uf_VNnKZPbGRL-tBOhaOf2LN14-akvvmuIppr99dYuQ,477
32
+ kisa_utils-0.43.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
33
+ kisa_utils-0.43.0.dist-info/top_level.txt,sha256=GFOLXZYqpBG9xtscGa2uGJAEiZ5NwsqHBH9NylnB29M,11
34
+ kisa_utils-0.43.0.dist-info/RECORD,,