atomicshop 2.12.1__py3-none-any.whl → 2.12.3__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.
Potentially problematic release.
This version of atomicshop might be problematic. Click here for more details.
- atomicshop/__init__.py +1 -1
- atomicshop/diff_check.py +74 -6
- atomicshop/file_io/csvs.py +29 -12
- {atomicshop-2.12.1.dist-info → atomicshop-2.12.3.dist-info}/METADATA +1 -1
- {atomicshop-2.12.1.dist-info → atomicshop-2.12.3.dist-info}/RECORD +8 -8
- {atomicshop-2.12.1.dist-info → atomicshop-2.12.3.dist-info}/LICENSE.txt +0 -0
- {atomicshop-2.12.1.dist-info → atomicshop-2.12.3.dist-info}/WHEEL +0 -0
- {atomicshop-2.12.1.dist-info → atomicshop-2.12.3.dist-info}/top_level.txt +0 -0
atomicshop/__init__.py
CHANGED
atomicshop/diff_check.py
CHANGED
|
@@ -38,7 +38,7 @@ class DiffChecker:
|
|
|
38
38
|
The object is 'None' by default, since there are objects that are needed to be provided in the
|
|
39
39
|
function input for that object. So, not always you know what your object type during class initialization.
|
|
40
40
|
:param check_object_display_name: string, name of the object to display in the message.
|
|
41
|
-
If not specified, the 'check_object' will be displayed.
|
|
41
|
+
If not specified, the provided 'check_object' will be displayed.
|
|
42
42
|
:param aggregation: boolean, if True, the object will be aggregated with other objects in the list of objects.
|
|
43
43
|
Meaning, that the object will be checked against the existing objects in the list, and if it is not
|
|
44
44
|
in the list, it will be added to the list. If it is in the list, it will be ignored.
|
|
@@ -62,6 +62,74 @@ class DiffChecker:
|
|
|
62
62
|
|
|
63
63
|
True: return updated dictionary on first cycle. This is the default.
|
|
64
64
|
False: don't return updated dictionary on first cycle.
|
|
65
|
+
|
|
66
|
+
--------------------------------------------------
|
|
67
|
+
|
|
68
|
+
Working example:
|
|
69
|
+
from atomicshop import diff_check
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# Example of checking list of dicts.
|
|
73
|
+
check_list_of_dicts = [
|
|
74
|
+
{'name': 'John', 'age': 25},
|
|
75
|
+
{'name': 'Alice', 'age': 30}
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
diff_checker = diff_check.DiffChecker(
|
|
79
|
+
check_object=check_list_of_dicts,
|
|
80
|
+
check_object_display_name='List of Dicts',
|
|
81
|
+
aggregation=True,
|
|
82
|
+
input_file_path='D:\\input\\list_of_dicts.json',
|
|
83
|
+
input_file_write_only=True,
|
|
84
|
+
return_first_cycle=True
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
result, message = diff_checker.check_list_of_dicts(
|
|
88
|
+
sort_by_keys=['name']
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# If result is not None, it means that the object was updated.
|
|
92
|
+
if result:
|
|
93
|
+
print(message)
|
|
94
|
+
|
|
95
|
+
--------------------------------------------------
|
|
96
|
+
|
|
97
|
+
Working example when you need to aggregate a list of dicts, meaning only new entries will be added to the list:
|
|
98
|
+
from atomicshop import diff_check
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
diff_checker = diff_check.DiffChecker(
|
|
102
|
+
check_object_display_name='List of Dicts',
|
|
103
|
+
aggregation=True,
|
|
104
|
+
input_file_path='D:\\input\\list_of_dicts.json',
|
|
105
|
+
input_file_write_only=True,
|
|
106
|
+
return_first_cycle=True
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
# Example of checking list of dicts.
|
|
110
|
+
check_list_of_dicts = [
|
|
111
|
+
{'name': 'John', 'age': 25},
|
|
112
|
+
{'name': 'Alice', 'age': 30}
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
diff_checker.check_object = check_list_of_dicts
|
|
116
|
+
result, message = diff_checker.check_list_of_dicts()
|
|
117
|
+
|
|
118
|
+
# If result is not None, it means that the object was updated.
|
|
119
|
+
if result:
|
|
120
|
+
print(message)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
check_list_of_dicts = [
|
|
124
|
+
{'name': 'John', 'age': 25},
|
|
125
|
+
{'name': 'Jessie', 'age': 50}
|
|
126
|
+
]
|
|
127
|
+
|
|
128
|
+
diff_checker.check_object = check_list_of_dicts
|
|
129
|
+
result, message = diff_checker.check_list_of_dicts()
|
|
130
|
+
|
|
131
|
+
if result:
|
|
132
|
+
print(message)
|
|
65
133
|
"""
|
|
66
134
|
|
|
67
135
|
# 'check_object' can be none, so checking if it not equals empty string.
|
|
@@ -130,13 +198,13 @@ class DiffChecker:
|
|
|
130
198
|
try:
|
|
131
199
|
if self.save_as == 'txt':
|
|
132
200
|
self.previous_content = file_io.read_file(
|
|
133
|
-
self.input_file_path, stderr=False, **print_kwargs)
|
|
201
|
+
self.input_file_path, stderr=False, **(print_kwargs or {}))
|
|
134
202
|
elif self.save_as == 'json':
|
|
135
203
|
self.previous_content = jsons.read_json_file(
|
|
136
|
-
self.input_file_path, stderr=False, **print_kwargs)
|
|
204
|
+
self.input_file_path, stderr=False, **(print_kwargs or {}))
|
|
137
205
|
except FileNotFoundError as except_object:
|
|
138
206
|
message = f"Input File [{Path(except_object.filename).name}] doesn't exist - Will create new one."
|
|
139
|
-
print_api(message, color='yellow', **print_kwargs)
|
|
207
|
+
print_api(message, color='yellow', **(print_kwargs or {}))
|
|
140
208
|
pass
|
|
141
209
|
|
|
142
210
|
# get the content of current function.
|
|
@@ -182,10 +250,10 @@ class DiffChecker:
|
|
|
182
250
|
if self.input_file_path:
|
|
183
251
|
if self.save_as == 'txt':
|
|
184
252
|
# noinspection PyTypeChecker
|
|
185
|
-
file_io.write_file(self.previous_content, self.input_file_path, **print_kwargs)
|
|
253
|
+
file_io.write_file(self.previous_content, self.input_file_path, **(print_kwargs or {}))
|
|
186
254
|
elif self.save_as == 'json':
|
|
187
255
|
jsons.write_json_file(
|
|
188
|
-
self.previous_content, self.input_file_path, use_default_indent=True, **print_kwargs)
|
|
256
|
+
self.previous_content, self.input_file_path, use_default_indent=True, **(print_kwargs or {}))
|
|
189
257
|
else:
|
|
190
258
|
message = f"Object didn't change: {self.check_object_display_name}"
|
|
191
259
|
|
atomicshop/file_io/csvs.py
CHANGED
|
@@ -84,15 +84,24 @@ def read_csv_to_list_of_lists(
|
|
|
84
84
|
csv_reader = csv.reader(file_object)
|
|
85
85
|
|
|
86
86
|
csv_list = list(csv_reader)
|
|
87
|
-
header = csv_list[0]
|
|
88
87
|
|
|
89
|
-
if
|
|
88
|
+
# Get the header if there is only something in the content.
|
|
89
|
+
if csv_list:
|
|
90
|
+
header = csv_list[0]
|
|
91
|
+
else:
|
|
92
|
+
header = []
|
|
93
|
+
|
|
94
|
+
if exclude_header_from_content and csv_list:
|
|
90
95
|
csv_list.pop(0)
|
|
91
96
|
|
|
92
97
|
return csv_list, header
|
|
93
98
|
|
|
94
99
|
|
|
95
|
-
def write_list_to_csv(
|
|
100
|
+
def write_list_to_csv(
|
|
101
|
+
file_path: str,
|
|
102
|
+
content_list: list,
|
|
103
|
+
mode: str = 'w'
|
|
104
|
+
) -> None:
|
|
96
105
|
"""
|
|
97
106
|
Function to write list object that each iteration of it contains dict object with same keys and different values.
|
|
98
107
|
|
|
@@ -103,15 +112,23 @@ def write_list_to_csv(file_path: str, content_list: list, mode: str = 'w') -> No
|
|
|
103
112
|
"""
|
|
104
113
|
|
|
105
114
|
with open(file_path, mode=mode) as csv_file:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
if len(content_list) > 0 and isinstance(content_list[0], dict):
|
|
116
|
+
# Treat the list as list of dictionaries.
|
|
117
|
+
header = content_list[0].keys()
|
|
118
|
+
|
|
119
|
+
# Create CSV writer.
|
|
120
|
+
writer = csv.DictWriter(csv_file, fieldnames=header, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
|
121
|
+
|
|
122
|
+
# Write header.
|
|
123
|
+
writer.writeheader()
|
|
124
|
+
# Write list of dits as rows.
|
|
125
|
+
writer.writerows(content_list)
|
|
126
|
+
# Else, treat the list as list of lists.
|
|
127
|
+
else:
|
|
128
|
+
# Create CSV writer.
|
|
129
|
+
writer = csv.writer(csv_file)
|
|
130
|
+
# Write list of lists as rows.
|
|
131
|
+
writer.writerows(content_list)
|
|
115
132
|
|
|
116
133
|
|
|
117
134
|
def get_header(file_path: str, print_kwargs: dict = None) -> list:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
atomicshop/__init__.py,sha256=
|
|
1
|
+
atomicshop/__init__.py,sha256=IVAETwFBOuR1wwKN05VRVYWganSHrqXew86vdZG64O8,123
|
|
2
2
|
atomicshop/_basics_temp.py,sha256=6cu2dd6r2dLrd1BRNcVDKTHlsHs_26Gpw8QS6v32lQ0,3699
|
|
3
3
|
atomicshop/_create_pdf_demo.py,sha256=Yi-PGZuMg0RKvQmLqVeLIZYadqEZwUm-4A9JxBl_vYA,3713
|
|
4
4
|
atomicshop/_patch_import.py,sha256=ENp55sKVJ0e6-4lBvZnpz9PQCt3Otbur7F6aXDlyje4,6334
|
|
@@ -9,7 +9,7 @@ atomicshop/config_init.py,sha256=z2RXD_mw9nQlAOpuGry1h9QT-2LhNscXgGAktN3dCVQ,249
|
|
|
9
9
|
atomicshop/console_output.py,sha256=AOSJjrRryE97PAGtgDL03IBtWSi02aNol8noDnW3k6M,4667
|
|
10
10
|
atomicshop/console_user_response.py,sha256=31HIy9QGXa7f-GVR8MzJauQ79E_ZqAeagF3Ks4GGdDU,3234
|
|
11
11
|
atomicshop/datetimes.py,sha256=ICr0_gQqWnIw4BuNtabrHzjSlwnZkBfhyCrOILs5xpU,14623
|
|
12
|
-
atomicshop/diff_check.py,sha256=
|
|
12
|
+
atomicshop/diff_check.py,sha256=R4G9QISkTQAnJDOKUE6pH6xJ-roMsUwlSd7eVjTkHWA,14517
|
|
13
13
|
atomicshop/dns.py,sha256=bNZOo5jVPzq7OT2qCPukXoK3zb1oOsyaelUwQEyK1SA,2500
|
|
14
14
|
atomicshop/domains.py,sha256=Rxu6JhhMqFZRcoFs69IoEd1PtYca0lMCG6F1AomP7z4,3197
|
|
15
15
|
atomicshop/emails.py,sha256=I0KyODQpIMEsNRi9YWSOL8EUPBiWyon3HRdIuSj3AEU,1410
|
|
@@ -104,7 +104,7 @@ atomicshop/etw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
104
104
|
atomicshop/etw/dns_trace.py,sha256=RaREpwJETAMZSd1Lhbg0sO3ugBMw3y1fSKdvP5NfTqM,5189
|
|
105
105
|
atomicshop/etw/etw.py,sha256=xVJNbfCq4KgRfsDnul6CrIdAMl9xRBixZ-hUyqiB2g4,2403
|
|
106
106
|
atomicshop/file_io/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
107
|
-
atomicshop/file_io/csvs.py,sha256=
|
|
107
|
+
atomicshop/file_io/csvs.py,sha256=oc4ijOHYzayx89DfW2_cktrf81kcGVFKUvKQDAljVrA,5300
|
|
108
108
|
atomicshop/file_io/docxs.py,sha256=6tcYFGp0vRsHR47VwcRqwhdt2DQOwrAUYhrwN996n9U,5117
|
|
109
109
|
atomicshop/file_io/file_io.py,sha256=FR84ihjGlr7Eqejo-_js4nBICVst31axD0bwX19S2eM,6385
|
|
110
110
|
atomicshop/file_io/jsons.py,sha256=q9ZU8slBKnHLrtn3TnbK1qxrRpj5ZvCm6AlsFzoANjo,5303
|
|
@@ -249,8 +249,8 @@ atomicshop/wrappers/socketw/socket_server_tester.py,sha256=AhpurHJmP2kgzHaUbq5ey
|
|
|
249
249
|
atomicshop/wrappers/socketw/socket_wrapper.py,sha256=aXBwlEIJhFT0-c4i8iNlFx2It9VpCEpsv--5Oqcpxao,11624
|
|
250
250
|
atomicshop/wrappers/socketw/ssl_base.py,sha256=k4V3gwkbq10MvOH4btU4onLX2GNOsSfUAdcHmL1rpVE,2274
|
|
251
251
|
atomicshop/wrappers/socketw/statistics_csv.py,sha256=t3dtDEfN47CfYVi0CW6Kc2QHTEeZVyYhc57IYYh5nmA,826
|
|
252
|
-
atomicshop-2.12.
|
|
253
|
-
atomicshop-2.12.
|
|
254
|
-
atomicshop-2.12.
|
|
255
|
-
atomicshop-2.12.
|
|
256
|
-
atomicshop-2.12.
|
|
252
|
+
atomicshop-2.12.3.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
|
|
253
|
+
atomicshop-2.12.3.dist-info/METADATA,sha256=dlGv8-kBilmNG_mToWm8PUJK9XwcjNFCKZc2-jtzdvc,10447
|
|
254
|
+
atomicshop-2.12.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
255
|
+
atomicshop-2.12.3.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
|
|
256
|
+
atomicshop-2.12.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|