morelists 0.1.7__py3-none-any.whl → 0.1.8__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.
morelists/__init__.py CHANGED
@@ -62,7 +62,8 @@ class GameList():
62
62
  immortal = True if expires == -1 else False
63
63
  perf_counter = time.time()
64
64
  expires += perf_counter
65
- self.list[expires] = {"name":item.get("name", ""), "type":item.get("type", "add"), "value":item.get("value", 0)}
65
+ nameExtension = "_" + str(perf_counter)
66
+ self.list[expires] = {"name":item.get("name", "") + nameExtension, "type":item.get("type", "add"), "value":item.get("value", 0), "nameExtension": nameExtension}
66
67
 
67
68
 
68
69
  if self.list[expires]["type"] not in ["add", "subtract", "multiply", "divide"]:
@@ -74,9 +75,6 @@ class GameList():
74
75
  self.list[expires]["value"] = defaultValue
75
76
  print(f"[WARNING]: GameList uses the key 'value' to store the value of each item. You seem to have not given it a value. Defaulted to {defaultValue}.")
76
77
 
77
- if self.list[expires]["name"] == "":
78
- print(f'[WARNING]: GameList uses the key \'name\' to track items. You seem to have not given it a value. This will make it hard to track and pop at a later time (before its expiration date). Defaulted to "".')
79
-
80
78
  if not immortal:
81
79
  self.expirationList[expires] = self.list[expires]
82
80
  self.flippedList[str(self.list[expires])] = expires
@@ -105,7 +103,10 @@ class GameList():
105
103
  immortal = True if expires == -1 else False
106
104
  perf_counter = time.time()
107
105
  expires += perf_counter
106
+ nameExtension = "_" + str(perf_counter)
108
107
  self.list[expires] = item
108
+ self.list[expires]["name"] += nameExtension
109
+ self.list[expires]["nameExtension"] = nameExtension
109
110
  if not immortal:
110
111
  self.expirationList[expires] = self.list[expires]
111
112
  self.flippedList[str(item)] = expires
@@ -174,6 +175,9 @@ class GameList():
174
175
  del self.expirationList[expiration]
175
176
 
176
177
  object.__getattribute__(self, "history").append((expiration, self.list, self.expirationList, self.flippedList, self.safeSum()))
178
+
179
+ if len(self.expirationList.keys()) == 0:
180
+ return
177
181
  expiration = min(self.expirationList.keys())
178
182
  except ValueError as e:
179
183
  print(f"[WARNING]: While updating the list, a new error appeared: {e}")
@@ -252,7 +256,7 @@ class GameList():
252
256
  name -- the name you gave the item in the list
253
257
  """
254
258
  perf_counter = time.time()
255
- pops = [(key, value) for key, value in self.list.items() if value["name"] == name]
259
+ pops = [(key, value) for key, value in self.list.items() if value["name"] == name + value["nameExtension"]]
256
260
  pops.sort(key=lambda a: a[0])
257
261
  if pops:
258
262
  stringedList = str(pops[0][1])
@@ -281,7 +285,7 @@ class GameList():
281
285
  name -- the name you gave the item in the list
282
286
  """
283
287
  perf_counter = time.time()
284
- pops = [value for value in self.list.values() if value["name"] == name]
288
+ pops = [value for value in self.list.values() if value["name"] == name + value["nameExtension"]]
285
289
  if pops:
286
290
  stringedList = str(pops[0])
287
291
 
@@ -309,7 +313,7 @@ class GameList():
309
313
  name -- the name you gave the item(s) in the list
310
314
  """
311
315
  perf_counter = time.time()
312
- pops = [value for value in self.list.values() if value["name"] == name]
316
+ pops = [value for value in self.list.values() if value["name"] == name + value["nameExtension"]]
313
317
  if pops:
314
318
  for x in range(len(pops)):
315
319
  stringedList = str(pops[x])
@@ -331,57 +335,34 @@ class GameList():
331
335
 
332
336
  object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, self.safeSum()))
333
337
 
334
- def remove(self, item):
335
- """
336
- Removes a specific item from the list (if it exists)
337
-
338
- Keyword arguments:
339
- name -- the name you gave the item(s) in the list
340
- """
341
- perf_counter = time.time()
342
- stringedList = str(item)
343
- if self.flippedList.get(stringedList, None):
344
- del self.list[self.flippedList[stringedList]]
345
- if self.flippedList[stringedList] in self.expirationList: del self.expirationList[self.flippedList[stringedList]]
346
- del self.flippedList[stringedList]
347
-
348
- if item["type"] == "add":
349
- self.addValue -= item["value"]
350
- elif item["type"] == "subtract":
351
- self.subtractValue -= item["value"]
352
- elif item["type"] == "multiply":
353
- self.multiplyValue -= (item["value"] - 1)
354
- else:
355
- self.divideValue -= (item["value"] - 1)
356
-
357
- object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, self.safeSum()))
358
-
359
- def unsafeRemove(self, item):
338
+ def remove(self, item: dict):
360
339
  """
361
340
  Removes a specific item from the list (if it exists)
362
341
 
363
- More unsafe compared to remove(item), so use only if you know what you are doing!
364
-
365
342
  Keyword arguments:
366
343
  name -- the name you gave the item(s) in the list
367
344
  """
368
345
  perf_counter = time.time()
369
- if item in self.list.values():
370
- stringedList = str(item)
371
- del self.list[dict(self.flippedList[stringedList])]
372
- if dict(self.flippedList[stringedList]) in self.expirationList: del self.expirationList[dict(self.flippedList[stringedList])]
373
- del self.flippedList[stringedList]
374
-
375
- if item["type"] == "add":
376
- self.addValue -= item["value"]
377
- elif item["type"] == "subtract":
378
- self.subtractValue -= item["value"]
379
- elif item["type"] == "multiply":
380
- self.multiplyValue -= (item["value"] - 1)
381
- else:
382
- self.divideValue -= (item["value"] - 1)
346
+ if not item.get("name", ""):
347
+ print("[WARNING]: Removing an item without a name might delete the wrong item! Make sure to give your items a name to remove the risk.")
348
+
349
+ for list_key, list_item in self.list.items():
350
+ if item + list_item["nameExtension"] == list_item["name"]:
351
+ del self.flippedList[str(list_item)]
352
+ if self.expirationList.get(list_key, None) == list_item: del self.expirationList[list_key]
353
+ del self.list[list_key]
354
+
355
+ if list_item["type"] == "add":
356
+ self.addValue -= list_item["value"]
357
+ elif list_item["type"] == "subtract":
358
+ self.subtractValue -= list_item["value"]
359
+ elif list_item["type"] == "multiply":
360
+ self.multiplyValue -= (list_item["value"] - 1)
361
+ else:
362
+ self.divideValue -= (list_item["value"] - 1)
383
363
 
384
- object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, self.safeSum()))
364
+ object.__getattribute__(self, "history").append((perf_counter, self.list, self.expirationList, self.flippedList, self.safeSum()))
365
+ break
385
366
 
386
367
  def __getattribute__(self, name):
387
368
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: morelists
3
- Version: 0.1.7
3
+ Version: 0.1.8
4
4
  Summary: A small and easy list you can add together like a math equation and has a expiration date for items. Mostly useful for games with stats from multiple sources. More lists will come soon.
5
5
  Home-page: https://github.com/EmanuelNorsk/enlist
6
6
  Author: Emanuel Odén Hesselroth
@@ -0,0 +1,6 @@
1
+ morelists/__init__.py,sha256=3QOKdfZbYWhQ2PwH0qNh36gf-mQFUw_SdkXWS4uKglw,16272
2
+ morelists-0.1.8.dist-info/licenses/LICENSE,sha256=-ASFHlrne1rk8zV57Qj01X2JB-D67ZHPMv1PtQhrbN8,32
3
+ morelists-0.1.8.dist-info/METADATA,sha256=ULdDN_JhZh3EkFubFVdgqx-l_TOCenoQfH78_5kJF-E,681
4
+ morelists-0.1.8.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
5
+ morelists-0.1.8.dist-info/top_level.txt,sha256=Zd7NosYzor-RcH_aD86FXJa3fQzWunYA4_FQS3Yodqo,10
6
+ morelists-0.1.8.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- morelists/__init__.py,sha256=ky5da3RAz0qV48RVl4Oh64TSf5Ua9w0MD0o-DNlgqvU,17010
2
- morelists-0.1.7.dist-info/licenses/LICENSE,sha256=-ASFHlrne1rk8zV57Qj01X2JB-D67ZHPMv1PtQhrbN8,32
3
- morelists-0.1.7.dist-info/METADATA,sha256=gJ6CXhFxL2-nPF0Q9n4Ev54im0SeRXE_yAujwfGDYe8,681
4
- morelists-0.1.7.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
5
- morelists-0.1.7.dist-info/top_level.txt,sha256=Zd7NosYzor-RcH_aD86FXJa3fQzWunYA4_FQS3Yodqo,10
6
- morelists-0.1.7.dist-info/RECORD,,