Skip to content

Instantly share code, notes, and snippets.

@dom96

dom96/.nim Secret

Created April 29, 2018 20:13
Show Gist options
  • Save dom96/eb2ae290d1f79233b330bccfd28437f4 to your computer and use it in GitHub Desktop.
Save dom96/eb2ae290d1f79233b330bccfd28437f4 to your computer and use it in GitHub Desktop.
var data: array[5, seq[string]]
proc refreshMensaData() {.async.} =
while true:
data.fill(@[])
var client = newAsyncHttpClient()
var thisweek = await client.getContent("target.url.example.com")
#[ here happens some stuff ]#
data[0].add(thisWeek.parseHtml()) # Guessing here
# timeout in seconds, i'm guessing you want to run this multiple times
await sleepAsync(10000)
when isMainModule:
asyncCheck refreshMensaData()
# serve the data
var server = newAsyncHttpServer()
proc cb(req: Request) {.async.} =
await req.respond(Http200, #[either html or json ]# ))
waitFor server.serve(Port(80), cb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment