diff --git a/main b/main index 04f5841..a6918d3 100755 Binary files a/main and b/main differ diff --git a/main.nim b/main.nim index de4961a..b6a1b3b 100644 --- a/main.nim +++ b/main.nim @@ -8,38 +8,45 @@ import std/json import std/strutils var client = newHttpClient() var html: string -#var node: XmlNode -proc do_another_loop( node : JsonNode, level : int, searchString : string = "",path :string = "H") = +proc do_another_loop[T]( node : T , level : int, searchString : string = "",path :string = "H") + +proc do_loop[T](node: T,level : int, searchString : string = "", path: string = "", key : string) = + if searchString == "" or node.contains(searchString): + stdout.write "|", path & "-" & key + #children of currentObj + if node.kind == JObject: + if searchString == "" or node.contains(searchString): + stdout.write("\n") + echo "childs: " + for y in node.keys: + stdout.write ", " ,y," [", node[y].kind,"] \n" + do_another_loop(node,level+1,searchString,path & "-" & key) + #children of currentObj + +proc do_array_loop(node : JsonNode, level : int, searchString : string = "", path: string = "") = + if searchString == "" or node.contains(searchString): + echo "Array Elements: ", node.getElems() + echo "Array Length", node.len() + echo "WWWWWWWWWWWWWWW" + for b in node: + echo "array_node_len: ", b.len()," ,subkind: " ,b.kind, "mainkind: ", node.kind + do_another_loop(b,level+1,searchString,path & "-" & $node) + #if node[a].kind == JString: + #echo "String: ", node[a] + #stdout.write "\n" + +proc do_another_loop[T]( node : T , level : int, searchString : string = "",path :string = "H") = if node.len() > 0: - for a in node.keys: - if node.kind == JObject: - #for i in 0 .. level: - if searchString == "" or a.contains(searchString): - #for x in 0..level: - # stdout.write " " - stdout.write "|", path & "-" & a + if node.kind == JObject: + for a in node.keys: if node[a].kind == JObject: - stdout.write("\n") - do_another_loop(node[a],level+1,searchString,path & "-" & a) - else: - if searchString == "" or a.contains(searchString): - stdout.write " [", node[a].kind, "]" - stdout.write("\n") - if node[a].kind == JArray: - if searchString == "" or a.contains(searchString): - echo "Array Elements: ", node[a].getElems() - echo "Array Length", node[a].len() - echo "WWWWWWWWWWWWWWW" - for b in node[a]: - echo b - do_another_loop(b,level,searchString,path & "-" & a) - - #stdout.write "\n" - else: - echo "\n--------" - - + do_loop(node[a],level,searchString,path, a) + elif node[a].kind == JArray: + do_array_loop(node[a],level,searchString,path) + elif node.kind == JArray: + do_array_loop(node,level,searchString,path) + echo "URL:" var url: string = "https://www.comparis.ch/immobilien/marktplatz/lenzburg/mieten?page=2"#readLine(stdin) echo "given url is: ",url @@ -68,7 +75,7 @@ try: #echo "JSON Node:", jsonNode #echo "node fields: ",jsonNode["props"]["pageProps"]["pageTitle"].getStr() let field = jsonNode.getFields() - do_another_loop(jsonNode,0,searchString = "resultItems") + do_another_loop(jsonNode,0,searchString = "") #echo "resultitem", jsonNode["resultItems"] # for a in jsonNode.keys: