Create Wolfram Notebook from WEB API JSON data​
​by Daniel Carvalho
I usually use DuckDuckGo search engine WEB API because it do not required key or any sort of logging, and it has good information about websites and so on...
With Import function we can do the WEB API call and get the message as Wolfram language associations
Just to check info, we can plot the text from related topics, according the JSON message data structured provided by DuckDuckGo web service
In[]:=
ddg=Import["https://api.duckduckgo.com/?q=Nicola+Tesla&format=json","RawJSON"];
Framed[#["Text"]]&/@ddg["RelatedTopics"]//Column
Out[]=
Nikola Tesla Category
Charles Proteus Steinmetz – a contemporaneous electrical pioneer in alternating current and high voltage research.
Michael Faraday - Michael Faraday was an English scientist who contributed to the study of electromagnetism and electrochemistry. His main discoveries include the principles underlying electromagnetic induction, diamagnetism and electrolysis.
Atmospheric electricity - Atmospheric electricity is the study of electrical charges in the Earth's atmosphere. The movement of charge between the Earth's surface, the atmosphere, and the ionosphere is known as the global atmospheric electrical circuit.
Nikola Tesla in popular culture - Nikola Tesla is portrayed in many forms of popular culture. The Serbian-American engineer has particularly been depicted in science fiction, a genre which is well suited to address his inventions; while often exaggerated, the fictionalized variants build mostly upon his own alleged claims or ideas.
Austro-Hungarian inventors
Serbian inventors
People of the Military Frontier
Austro-Hungarian engineers
Graz University of Technology alumni
Great Officers of the Order of St. Sava
Serbian engineers
American futurologists
Serbian scientists
Wireless energy transfer
Recipients of the Order of the Yugoslav Crown
Grand Crosses of the Order of St. Sava
Mental calculators
Austro-Hungarian Serbs
Google Doodles
People associated with electricity
Serbian emigrants to the United States
19th-century American engineers
Grand Crosses of the Order of the White Lion
American eugenicists
Radio pioneers
IEEE Edison Medal recipients
Habsburg Serbs
American humanists
Members of the Serbian Academy of Sciences and Arts
19th-century Serbian people
20th-century Serbian people
Austro-Hungarian emigrants to the United States
Serbs of Croatia
American mechanical engineers
We can inspect the DuckDuckGo message data with a dataset:
Dataset[ddg]
Out[]=
Abstract
Nikola Tesla was a Serbian-American inventor, electrical engineer, mechanical engineer, and futurist best known for his contributions to the design of the modern alternating current electricity supply system. Born and raised in the Austrian Empire, Tesla studied engineering and physics in the 1870s without receiving a degree, gaining practical experience in the early 1880s working in telephony and at Continental Edison in the new electric power industry. In 1884 he emigrated to the United States, where he became a naturalized citizen. He worked for a short time at the Edison Machine Works in New York City before he struck out on his own. With the help of partners to finance and market his ideas, Tesla set up laboratories and companies in New York to develop a range of electrical and mechanical devices.
AbstractSource
Wikipedia
AbstractText
Nikola Tesla was a Serbian-American inventor, electrical engineer, mechanical engineer, and futurist best known for his contributions to the design of the modern alternating current electricity supply system. Born and raised in the Austrian Empire, Tesla studied engineering and physics in the 1870s without receiving a degree, gaining practical experience in the early 1880s working in telephony and at Continental Edison in the new electric power industry. In 1884 he emigrated to the United States, where he became a naturalized citizen. He worked for a short time at the Edison Machine Works in New York City before he struck out on his own. With the help of partners to finance and market his ideas, Tesla set up laboratories and companies in New York to develop a range of electrical and mechanical devices.
AbstractURL
https://en.wikipedia.org/wiki/Nikola_Tesla
Answer
AnswerType
Definition
DefinitionSource
DefinitionURL
Entity
person
Heading
Nikola Tesla
Image
/i/a9c448ae.jpeg
ImageHeight
200
ImageIsLogo
0
ImageWidth
149
Infobox

…
2

Redirect
RelatedTopics
{
…
35
}
Results
{}
Type
A
rows 1–20 of 21
This is a function to parse DuckDuckGo message and create a notebook and highlights some details such as abstract, image and related links (and make it clickable):
In[]:=
ddgQuery[query_String]:=Module[{ddgMessage=Import["https://api.duckduckgo.com/?format=json&q="<>URLEncode[query],"RawJSON"]},​​CellPrint[Flatten@{TextCell[ddgMessage["Heading"],"Section"],​​TextCell[ddgMessage["Abstract"],"Text"],​​TextCell[Import["https://www.duckduckgo.com/"<>ddgMessage["Image"]],"Text"],​​TextCell[Row[{#["Text"]," ",Hyperlink["»",#["FirstURL"]]}],"Item"]&/@ddgMessage["RelatedTopics"]}]]
Now test the function searching for Nicola Tesla info.
Any hint to make it better will be appreciated! :-)
In[]:=
ddgQuery["Nicola Tesla"]

Nikola Tesla

Nikola Tesla was a Serbian-American inventor, electrical engineer, mechanical engineer, and futurist best known for his contributions to the design of the modern alternating current electricity supply system. Born and raised in the Austrian Empire, Tesla studied engineering and physics in the 1870s without receiving a degree, gaining practical experience in the early 1880s working in telephony and at Continental Edison in the new electric power industry. In 1884 he emigrated to the United States, where he became a naturalized citizen. He worked for a short time at the Edison Machine Works in New York City before he struck out on his own. With the help of partners to finance and market his ideas, Tesla set up laboratories and companies in New York to develop a range of electrical and mechanical devices.
◼
  • Nikola Tesla Category
    »