Skip to content

Instantly share code, notes, and snippets.

@juancarlospaco
Created April 9, 2020 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juancarlospaco/60fcd812a2b8c294ade7797d485e1c88 to your computer and use it in GitHub Desktop.
Save juancarlospaco/60fcd812a2b8c294ade7797d485e1c88 to your computer and use it in GitHub Desktop.
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