sdf
This commit is contained in:
parent
5ae9aca08c
commit
d45b21d134
72
main.nim
72
main.nim
@ -6,48 +6,82 @@ import std/os
|
||||
import scrap
|
||||
import std/json
|
||||
import std/strutils
|
||||
import std/tables
|
||||
import std/macros
|
||||
|
||||
var client = newHttpClient()
|
||||
var html: string
|
||||
#
|
||||
# main_loop <------------
|
||||
# | | |
|
||||
# normal_loop array_loop |
|
||||
# (var node) (var array[]) |
|
||||
# | |
|
||||
# ----->-------------------
|
||||
#
|
||||
|
||||
proc do_another_loop[T]( node : T , level : int, searchString : string = "",path :string = "H")
|
||||
proc dbg_dl(level : int)=
|
||||
for a in 0..level:
|
||||
stdout.write " "
|
||||
stdout.write level
|
||||
stdout.write("[do_loop]")
|
||||
proc dbg_ml(level : int)=
|
||||
for a in 0..level:
|
||||
stdout.write " "
|
||||
stdout.write level
|
||||
stdout.write("[main_loop]")
|
||||
proc dbg_al(level : int)=
|
||||
for a in 0..level:
|
||||
stdout.write " "
|
||||
stdout.write level
|
||||
stdout.write("[array_loop]")
|
||||
|
||||
proc main_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
|
||||
dbg_dl(level)
|
||||
stdout.write path & "-" & key
|
||||
if node.kind == JObject:
|
||||
if searchString == "" or node.contains(searchString):
|
||||
stdout.write("\n")
|
||||
dbg_dl(level)
|
||||
echo "childs: "
|
||||
for y in node.keys:
|
||||
dbg_dl(level)
|
||||
stdout.write path & "-" & y," [", node[y].kind,"] \n"
|
||||
do_another_loop(node,level+1,searchString,path & "-" & key)
|
||||
#children of currentObj
|
||||
main_loop(node[y],level+1,searchString,path & "-" & key)
|
||||
|
||||
proc do_array_loop(node : JsonNode, level : int, searchString : string = "", path: string = "",key :string = "") =
|
||||
if searchString == "" or node.contains(searchString):
|
||||
dbg_al(level)
|
||||
echo "Key: ",key
|
||||
echo "Array Elements: ", node.getElems()
|
||||
#dbg_al(level)
|
||||
#echo "Array Elements: ", node.getElems()
|
||||
dbg_al(level)
|
||||
echo "Array Length", node.len()
|
||||
echo "WWWWWWWWWWWWWWW"
|
||||
for b in node:
|
||||
echo "\nnode , b: ", b, "array_node_len: ", b.len()," ,subkind: " ,b.kind, "mainkind: ", node.kind
|
||||
do_another_loop(b,level+1,searchString,path & "-" & key)
|
||||
#if node[a].kind == JString:
|
||||
#echo "String: ", node[a]
|
||||
#stdout.write "\n"
|
||||
dbg_al(level)
|
||||
for b in node.getElems:
|
||||
dbg_al(level)
|
||||
echo "node : ", "array_node_len: ", b.len()," ,subkind: " ,b.kind, "mainkind: ", node.kind
|
||||
main_loop(b,level+1,searchString,path & "-A-" & key)
|
||||
|
||||
|
||||
proc do_another_loop[T]( node : T , level : int, searchString : string = "",path :string = "H") =
|
||||
proc main_loop[T]( node : T , level : int, searchString : string = "",path :string = "H") =
|
||||
if node.len() > 0:
|
||||
if node.kind == JObject:
|
||||
var elem = node.getElems()
|
||||
for b in node.pairs:
|
||||
dbg_ml(level)
|
||||
echo "element: ",b, " path: ",path
|
||||
for a in node.keys:
|
||||
if node[a].kind == JObject:
|
||||
do_loop(node[a],level,searchString,path, a)
|
||||
elif node[a].kind == JArray:
|
||||
do_array_loop(node[a],level,searchString,path,a)
|
||||
elif node[a].kind == JString:
|
||||
echo "String: ",path & "-" & $node[a]
|
||||
do_array_loop(node[a],level+1,searchString,path,a)
|
||||
#elif node[a].kind == JString:
|
||||
# dbg_ml(level)
|
||||
# echo "String: ",path & "-" & $node[a]
|
||||
elif node.kind == JArray:
|
||||
do_array_loop(node,level,searchString,path)
|
||||
|
||||
@ -79,7 +113,7 @@ try:
|
||||
#echo "JSON Node:", jsonNode
|
||||
#echo "node fields: ",jsonNode["props"]["pageProps"]["pageTitle"].getStr()
|
||||
let field = jsonNode.getFields()
|
||||
do_another_loop(jsonNode,0,searchString = "")
|
||||
main_loop(jsonNode,0,searchString = "")
|
||||
|
||||
#echo "resultitem", jsonNode["resultItems"]
|
||||
# for a in jsonNode.keys:
|
||||
@ -87,7 +121,7 @@ try:
|
||||
# if jsonNode[a].len() > 0:
|
||||
# for b in jsonNode[a].keys:
|
||||
# echo ">>>"
|
||||
# do_another_loop(jsonNode[a][b])
|
||||
# main_loop(jsonNode[a][b])
|
||||
# else:
|
||||
# echo "---------------"
|
||||
finally:
|
||||
|
Loading…
Reference in New Issue
Block a user