Electron-Svelte-Recipe-Planner/NimRecipe/oldcode/densityTable.nim
2021-12-16 00:55:59 -05:00

37 lines
1.2 KiB
Nim

import strutils, tables, marshal
var counter = 0
var returntable = initOrderedTable[string, volumeConversion]()
var builder : seq[string]
proc getValue(input : string) : string =
return input.split("td>")[1].split("<")[0]
for line in readFile("uwu.html").split("\n"):
echo line
case counter:
of 0:
if line.contains("href"):
builder.add(line.split("""">""")[1].split("<")[0])
else: builder.add(line.split("th>")[1].split("<")[0])
of 1, 3: builder.add(getValue line)
of 2:
case line:
of " ":
builder.add("0")
else:
builder.add(getValue line)
else:
echo "this should be impossible"
case counter:
of 0, 1, 2: inc counter
of 3:
counter = 0
try:
returntable[builder[0]] = (builder[1], builder[2], parseInt(builder[3]))
except: returntable[builder[0]] = (builder[1], builder[2],
parseInt(builder[3].split("to ")[1]))
builder.setLen(0)
else: echo "this should be impossible"
writeFile("densityTable.json", $$returntable)