morelists 0.1.6__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,12 +75,9 @@ 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
- self.flippedList[json.dumps(self.list[expires])] = expires
80
+ self.flippedList[str(self.list[expires])] = expires
83
81
 
84
82
  if item["type"] == "add":
85
83
  self.addValue += item["value"]
@@ -105,10 +103,13 @@ 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
- self.flippedList[json.dumps(item)] = expires
112
+ self.flippedList[str(item)] = expires
112
113
 
113
114
  if item["type"] == "add":
114
115
  self.addValue += item["value"]
@@ -169,11 +170,14 @@ class GameList():
169
170
  else:
170
171
  self.divideValue -= (self.list[expiration]["value"] - 1)
171
172
 
172
- del self.flippedList[json.dumps(self.list[expiration])]
173
+ del self.flippedList[str(self.list[expiration])]
173
174
  del self.list[expiration]
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,10 +256,10 @@ 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
- stringedList = json.dumps(pops[0][1])
262
+ stringedList = str(pops[0][1])
259
263
 
260
264
  item = self.list[self.flippedList[stringedList]]
261
265
  del self.list[self.flippedList[stringedList]]
@@ -281,9 +285,9 @@ 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
- stringedList = json.dumps(pops[0])
290
+ stringedList = str(pops[0])
287
291
 
288
292
  item = self.list[self.flippedList[stringedList]]
289
293
  del self.list[self.flippedList[stringedList]]
@@ -309,10 +313,10 @@ 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
- stringedList = json.dumps(pops[x])
319
+ stringedList = str(pops[x])
316
320
 
317
321
 
318
322
  item = self.list[self.flippedList[stringedList]]
@@ -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 = json.dumps(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 = json.dumps(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.6
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=Huivier40-MDWRl6Z5KUW4wpitVbEnRQxP1eU6XyKXI,17066
2
- morelists-0.1.6.dist-info/licenses/LICENSE,sha256=-ASFHlrne1rk8zV57Qj01X2JB-D67ZHPMv1PtQhrbN8,32
3
- morelists-0.1.6.dist-info/METADATA,sha256=EENJoIr31AYnyAUDbglTcVyUFOBnxScNSoWjJql5LDc,681
4
- morelists-0.1.6.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
5
- morelists-0.1.6.dist-info/top_level.txt,sha256=Zd7NosYzor-RcH_aD86FXJa3fQzWunYA4_FQS3Yodqo,10
6
- morelists-0.1.6.dist-info/RECORD,,