Created
April 9, 2020 05:52
-
-
Save juancarlospaco/60fcd812a2b8c294ade7797d485e1c88 to your computer and use it in GitHub Desktop.
Wikipedia as DNS Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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