Skip to content

Instantly share code, notes, and snippets.

@juancarlospaco
Created April 9, 2020 05:52
Embed
What would you like to do?
Wikipedia as DNS Server
import httpclient, json, xmltree, q
proc wikipediaDns*(name: string): string {.inline.} =
const w = "http://en.wikipedia.org/w/api.php?action=query&prop=info&inprop=url&format=json&limit=1&titles="
let hc = newHttpClient()
for x in hc.getContent(w & name).parseJson{"query", "pages"}.pairs:
for u in q(hc.getContent(x.val{"fullurl"}.getStr)).select"table.infobox tbody tr a[href*=http]":
return u.attr"href"
echo wikipediaDns("Nim-lang")
echo wikipediaDns("OpenStreetMap")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment