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