all stats

pii's stats

guessed the most

namecorrect guessesgames togetherratio

were guessed the most by

namecorrect guessesgames togetherratio

entries

round #24

submitted at
3 likes

guesses
comments 0

post a comment


24.zip Zip archive data, at least v2.0 to extract, compression method=store
dir 24
main.py ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os, json, ntpath, shutil

class Node():
	def __init__(self, key, data, path):
		self.key = key # must be a string
		self.data = data
		self.path = path

	def getLeft(self):
		if os.path.isdir(self.path + "left/"):
			p = self.path + "left/"
			f = [x for x in os.listdir(p) if x.endswith(".json")][0]
			obj = json.load(open(f))
			node = Node(obj["key"], obj["data"], obj["path"])
			return node
		return None

	def getRight(self):
		if os.path.isdir(self.path + "right/"):
			p = self.path + "right/"
			f = [x for x in os.listdir(p) if x.endswith(".json")][0]
			obj = json.load(open(f))
			node = Node(obj["key"], obj["data"], obj["path"])
			return node
		return None

	def getParent(self):
		p = self.path.split('/')[1:-1]
		if p[-1] != "tree":
			p = f"/{'/'.join(p[:-1])}/"
			f = [x for x in os.listdir(p) if x.endswith(".json")][0]
			obj = json.load(open(f))
			node = Node(obj["key"], obj["data"], obj["path"])
			return node
		return None

	def write(self):

		if not os.path.isdir(self.path): os.makedirs(self.path, exist_ok=True)
		f = open(self.path + self.key + ".json", "w+")
		payload = {"path": self.path, "key": self.key, "data": self.data}
		json.dump(payload, f)
		f.close()

class Entry:
	def __init__(self):
		pass

	def get(self, key, default=None):
		path = os.path.dirname(os.path.realpath(__file__)) + "/tree/"
		while 1:
			if not os.path.isdir(path):
				break
			else:
				data = path + [x for x in os.listdir(path) if x.endswith(".json")][0]
				fkey = ntpath.basename(data)[:-5]
				if fkey == key:
					obj = json.load(open(data))
					return obj["data"]
				elif key >= fkey: path += "right/"
				else: path += "left/"
		return default

	def insert(self, key, value):
		path = os.path.dirname(os.path.realpath(__file__)) + "/tree/"
		while 1:
			if not os.path.isdir(path) or not len(ld := os.listdir(path)):
				node = Node(key, value, path)
				node.write()
				return self
			else:
				data = path + [x for x in ld if x.endswith(".json")][0]
				fkey = ntpath.basename(data)[:-5]
				if fkey == key:
					node = Node(key, value, path)
					node.write()
					return self
				elif key >= fkey: path += "right/"
				else: path += "left/"

	def clean(self): # erases the "memory"
		path = os.path.dirname(os.path.realpath(__file__)) + "/tree/"
		shutil.rmtree(path)
		os.mkdir(path)
dir __MACOSX
._24 AppleDouble encoded Macintosh file
1
cg: couldn't decode file contents