forked from nushell/nu_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwolframalpha.nu
More file actions
21 lines (19 loc) · 810 Bytes
/
wolframalpha.nu
File metadata and controls
21 lines (19 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# The API requires an App ID
# https://developer.wolframalpha.com/
let appID = $env.WOLFRAMALPHA_APPID
#Fetch simple answer from WolframAlpha API
def wolfram [...query
] {
let query_string = ($query | str join " ")
let result = (http get ("https://api.wolframalpha.com/v1/result?" + ([[key value]; [appid $appID] [i $query_string]] | url build-query)))
$result + ""
}
#Fetch image with full answer from WolframAlpha API
def wolframimg [...query
] {
let query_string = ($query | str join " ")
let filename = ($query_string + ".png")
let link = ("https://api.wolframalpha.com/v1/simple?" + ([[key value]; [appid $appID] [i $query_string]] | url build-query) + "&background=F5F5F5&fontsize=20")
http get $link | save $filename
echo ("Query result saved in file: " + $filename)
}