How to read data response from Wikidata API? - javascript

I am making a ReactJS application to show information about people when they search for it. I am trying to use MediaWiki to get the information about a person from Wikipedia. I am making an API call and the response is very weird. I am getting this whole bunch of "claims" in the API response from which I don't know how to take the useful info
This is the response I get:
Now what should I do with these claims? The information itself is scattered there. For example: "Date of birth" key is in some other claim and the value of "Date of death" is in some other claim. I want to show information like this in my page:
How can I do it? I couldn't get any guide for this.

All information you need for item Q2038656 is in your response. For example:
P18 is image - located in P18/mainsnak/datavalue/value/Vinod Khanna at Esha Deol's wedding at ISCKON temple 11 (cropped).jpg (check here how to get the link to the image)
P19 is place of birth - in P19/mainsnak/datavalue/value/id/Q1113311 (you can get the name of this item by this query: Peshawar)
P569 is date of birth - in P569/mainsnak/datavalue/value/time/+1946-10-06T00:00:00Z
...continue in the same way for all other properties.

Related

HERE autosuggest get complete address informations

I'm currently working with HERE API, using autosuggest to get my results.
In the adress object of each response I only got "label" who look like this :
"address": { "label": "Resort Mark Brandenburg, An der Seepromenade 20, 16816 Neuruppin, Germany" },
Is there a way to optain complete informations like discover or autocomplete do ?
Like having countryCode, city, street in the address object ?
On this page https://developer.here.com/documentation/geocoding-search-api/api-reference-swagger.html at autosuggest menu we can see all the informations in the response samples.
I'm using this query at the moment :
https://autosuggest.search.hereapi.com/v1/autosuggest?apiKey=MYAPIKEY&result_types=address,place&in=bbox:0.5833,42.9667,2.241295,44.210550&in=countryCode:FRA&q=apitol&limit=5&content-type=application/json&lang=fr-fr
Add this parameter "&show=details" for show address details.
If some additional fields to be rendered in the response, then you have to pass the "show" tag in the request query string. Please note that some of the fields involve additional webservice calls and can increase the overall response time.
More details regarding "show" tag are covered in below API specs.
https://developer.here.com/documentation/geocoding-search-api/api-reference-swagger.html
Sample Request Query.
https://autosuggest.search.hereapi.com/v1/autosuggest?apiKey=YOUR_API_KEY&result_types=address,place&in=bbox:0.5833,42.9667,2.241295,44.210550&in=countryCode:FRA&q=apitol&limit=5&content-type=application/json&lang=fr-fr&show=details

Is There anyone who knows what this piece of code does?

I am very new to javascript .. and my teacher provided us with this piece of code along with html and css file which on any date you enter gives you images of mars taken from ISS..
Would anyone care to explain what is happening inside the data: {} and how to get such API URL'S? I mean from where do we get that?
var input_box=$('#div-date input');
var button=$('#div-button button');
var container2=$('#container2');
button.click(function()
{
$.ajax({
method: "GET",
url: "https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos",
data:
{
earth_date:parseInt(input_box.val().split('/')[2]).toString()+"-
"+parseInt(input_box.val().split('/')[1]).toString()+"-
"+parseInt(input_box.val().split('/')[0]).toString(),
api_key:"zrVafsMHD8r1SC8mHyg91mnNguuzdIoPRXGD1BvS"
},
The ajax method is a call to NASA endpoint where you are doing a GET call to the URL. I thinks this is clear.
Now, what does data?
earth_date is a value with the actual date parsed to a specific format. It get the date from the input_box with format 00/00/0000 and parse to format 0000-00-00
api_key is the key you need to authenticate and get the data.
And data itself is the way to send variables into URL. So, your url looks like this:
https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?earth_date=YOUR_DATE&api_key=YOUR_API_KEY
Note that is compound by:
url+ ?earth_date + api_key.
Updated to answer the question:
The API key is a way to secure the API.
An API key is a way to identify who is calling the endpoint. So only calls that have the API key will be able to reach the endpoint (or whatever the developer want).
Is an string generated by the owner so the only way to get the API key is NASA to give it to you. I suppose NASA give free API keys, but is not a "general string" or something like that. Every organization will secure their apis in a way, NASA provide api keys to reach his 'free' endpoints.
The code in the data transform the date format '30/12/2019' to '2019-12-30' since only the later format is valid for the request.

Using Wikia API

I am trying to access the X-men API on wikia, to try and extract the name and image of each character, to then be used on a SPA using javascript.
This is the link too the page on the wiki:
http://x-men.wikia.com/wiki/Category:Characters
I cannot for the life of me figure out how to access the API. It doesn't seem to be RESFTful, and that's all I have any experience in.
Has anyone used the Wikia API successfully before? I can get some articles and such, but nothing useful.
(The documentation is shocking, been searching around for hours.)
Probably you have already found a solution, but I think you should write something like this:
import requests
xmen_url = "http://x-men.wikia.com/api/v1/Articles/List?expand=1&category=Characters&limit=10000"
r = requests.get(xmen_url)
response = r.json()
# print response
a = 0
for item in response['items']:
a += 1
print("{}\t{}\t({})".format(str(a),item['title'].encode(encoding='utf-8'),item['id']))
This will print a list of all the articles of the category Characters (I think there also some subcategories, you should check). If you want to take a deeper look at the json file you can uncomment the commented code.
Hope it helps.

Scraping a webpage with python to get onclick values

First of all I have to say: be patient with me because I am not familiar with the argument that I am going to illustrate you.
I'd like to download the intraday historical values of some equities on Frankfurt Boerse website. Let me take this equity for example: http://www.boerse-frankfurt.de/en/equities/adidas+ag+DE000A1EWWW0/price+turnover+history/tick+data#page=1
As you can see there are two options: trades on Frankfurt and trades on Xetra. I'd love to download the latters. I tried to scrape the data but my knowledge of python is very poor.
How can I 'select' the desired onclick option?
Thanks in advance for your replies. Regards
Ps: For your information, I noted the following fact inspecting the Xetra element: it changes value when I move on to next page and if I come back the value is again different. Here an example: first time on page 1 I got
a onclick="d39081344_fkt_set_par('6');d39081344_fkt_set_active(this);" class="brs_d39081344_li current last"
, then I moved on to page 2 and I got
a onclick="d51109535_fkt_set_par('6');d51109535_fkt_set_active(this);" class="brs_d51109535_li current last" and coming back to page 1 I got a onclick="d96086211_fkt_set_par('6');d96086211_fkt_set_active(this);" class="brs_d96086211_li current last"
The trick is to look at what calls are made when you navigate through the pages. Your browser's network analysis tool is invaluable for this. When I go from page to page, a POST is made to 'http://www.boerse-frankfurt.de/en/parts/boxes/history/_tickdata_full.m with data about the request.
Then the goal is to replicate and loop the requests using python. Here is code to get you started:
import requests
r = requests.post('http://www.boerse-frankfurt.de/en/parts/boxes/history/_tickdata_full.m', data={'component_id':'PREKOP97077bf9dec39f14320bf9d40b636c7c589', 'page':"3", 'page_size':'50', 'boerse_id':'6', 'titel':'Tick-Data', 'lang':'en', 'text':'LOcbaec84ecad1b94ad2fd257897c87361', 'items_per_page':'50', 'template':'0', 'pages_total':'50', 'use_external_secu':'1', 'item_count':'2473', 'include_url':'/parts/boxes/history/_tickdata_full.m', 'ag':'291', 'secu':'291', })
print r.text #here is your data of interest, it still needs to be parsed
That is the general idea. You would then put that in a loop, adding one to the page parameter each time.

How to retrieve the list of positions including all the fields using the LinkedIn javascript sdk?

I want to get the id, title, summary, start-date, end-date, is-current and company name for each position that a LinkedIn member has entered on its profile.
I tested a query on the REST Console and I got the desired result. The query is "https://api.linkedin.com/v1/people/~/positions:(id,title,summary,start-date,end-date,is-current,company)?format=json".
The problem is that when I try to do the same thing using the LinkedIn javascript SDK I'm not getting the whole list of fields for each position. I'm getting the complete list of positions, but not all the fields for each position.
This is the call that I'm doing with the javascript SDK:
//in this function I'm specifying the list of fields that I want to retrieve for each position
//but I'm getting only some fields (id, start-date and end-date)
function getProfileData() {
IN.API.Raw("/people/~/positions:(id,title,summary,start-date,end-date,is-current,company)?format=json").result(onSuccess).error(onError);
}
Somebody has any idea of what I need to do to get the same result than using the REST Console?
Requesting URL is wrong.
Use following for positions
https://api.linkedin.com/v1/people/~:(id,positions)?format=json
Use following for locations
https://api.linkedin.com/v1/people/~:(id,location)?format=json
If you want to retrieve your profile data use this,
IN.API.Profile("me")
.fields([
"firstName","lastName","headline","positions:(company,title,summary,startDate,endDate,isCurrent)","industry",
"location:(name,country:(code))","pictureUrl","publicProfileUrl","emailAddress",
"educations","dateOfBirth"])
.result(onSuccess)
.error(onError);
(or) If you want to retrieve other profile data then replace "me" with "<public profile url>"
IN.API.Profile("url=https://nl.linkedin.com/in/williamhgates")
.fields([
"firstName","lastName","headline","positions:(company,title,summary,startDate,endDate,isCurrent)","industry",
"location:(name,country:(code))","pictureUrl","publicProfileUrl","emailAddress",
"educations","dateOfBirth"])
.result(onSuccess)
.error(onError);

Categories