-
Notifications
You must be signed in to change notification settings - Fork 2
/
tree.py
110 lines (67 loc) · 2.31 KB
/
tree.py
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from anytree import Node, RenderTree
from anytree.exporter import DotExporter
import pymongo
import pprint
from video import Video
class Simple:
def __init__(self, a, b):
self.a = a
self.b = b
def toString(self):
return "a: " + str(self.a) + ", b: " + self.b
CLIENT = pymongo.MongoClient("mongodb://py-user:[email protected]:27017,cluster0-shard-00-01-gm9y9.mongodb.net:27017,cluster0-shard-00-02-gm9y9.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority")
DB = CLIENT['ReSeed']
COL = DB['posts']
count = 0
l = []
def recurse(vid, parent):
global count
global l
# if count > 150:
# print("big count")
# return None
# print("hello\n")
# print(vid.toString())
# print("count = ", count)
l.append(vid.id)
vidNode = Node(vid.toString(), parent=parent)
count+=1
children = vid.recs
# print(children)
for child in children:
# ['parentID', 'childID']
# ['red', 'green']
# red, green -> oh fuck thats already in the dict
# search db again to find something thats red and NOT GREEN
childID = child[1]
# print(childID)
childDBentry = COL.find_one({"id": childID})
# print(childDBentry)
if childDBentry != None:
childVideoObj = Video('null', childDBentry, 1)
if childID not in l:
recurse(childVideoObj, vidNode)
else:
count += 0
# here we can check what the child video is
# we can check if the child video is a video already in the graph (using a list)
# oh shit, this child is actually already in the graph
# solutions
# skip the branch
pp = pprint.PrettyPrinter(indent=4)
rootVid = COL.find_one()
# pp.pprint(rootVid)
a = Node("a")
# b = Node("b", parent=a)
# b2 = Node("b2", parent=a)
# c2 = Node("c2", parent=b2)
# d2 = Node("d2", parent=b2)
# c = Node("c", parent=b)
# d = Node("d", parent=b)
# e = Node(3, parent=d)
# f = Node(Simple(3, 'hello').toString(), parent=e)
# g = Node(rootVidObj.toString(), parent=f)
rootVidObj = Video('null', rootVid, 1)
rootChildren = rootVidObj.recs
recurse(rootVidObj, a)
DotExporter(a).to_picture("d.png")